Fix build breakage on Travis-CI

Travis uses an older version of GCC which doesn't seem to support C99
mode by default. This fixes it by moving the variable declarations out
of the for loop and to the beginning of the function.
pull/13/head
nirenjan 2017-07-27 17:16:20 -07:00
parent dc352c58da
commit 74eeb27ad4
3 changed files with 14 additions and 6 deletions

View File

@ -22,6 +22,7 @@ int libusb_init(libusb_context **ctx)
int pid; int pid;
int parsed; int parsed;
FILE *dev_list; FILE *dev_list;
int i;
/* /*
* Technically, libusb_init can be called with a NULL context pointer, * Technically, libusb_init can be called with a NULL context pointer,
@ -73,7 +74,7 @@ int libusb_init(libusb_context **ctx)
/* Rewind and read the file again, but now put them into the device list */ /* Rewind and read the file again, but now put them into the device list */
rewind(dev_list); rewind(dev_list);
for (int i = 0; i < dev_count && !feof(dev_list); i++) { for (i = 0; i < dev_count && !feof(dev_list); i++) {
/* Set the base fields */ /* Set the base fields */
tmp_ctx->devices[i].context = tmp_ctx; tmp_ctx->devices[i].context = tmp_ctx;
tmp_ctx->devices[i].index = i; tmp_ctx->devices[i].index = i;
@ -132,13 +133,14 @@ ssize_t libusb_get_device_list(libusb_context *ctx, libusb_device ***list)
*/ */
libusb_device **tmp_list = calloc(ctx->num_devices + 1, sizeof(*tmp_list)); libusb_device **tmp_list = calloc(ctx->num_devices + 1, sizeof(*tmp_list));
libusb_device *dev; libusb_device *dev;
int i;
if (tmp_list == NULL) { if (tmp_list == NULL) {
return LIBUSB_ERROR_NO_MEM; return LIBUSB_ERROR_NO_MEM;
} }
/* Initialize the list with pointers to the individual devices */ /* Initialize the list with pointers to the individual devices */
for (int i = 0; i < ctx->num_devices; i++) { for (i = 0; i < ctx->num_devices; i++) {
dev = &(ctx->devices[i]); dev = &(ctx->devices[i]);
/* Increment the refcount */ /* Increment the refcount */
dev->ref_count += 1; dev->ref_count += 1;
@ -151,8 +153,10 @@ ssize_t libusb_get_device_list(libusb_context *ctx, libusb_device ***list)
void libusb_free_device_list(libusb_device **list, int unref_devices) void libusb_free_device_list(libusb_device **list, int unref_devices)
{ {
libusb_device **dev;
if (unref_devices) { if (unref_devices) {
for (libusb_device **dev = list; *dev; dev++) { for (dev = list; *dev; dev++) {
/* Decrement the refcount */ /* Decrement the refcount */
(*dev)->ref_count -= 1; (*dev)->ref_count -= 1;
} }
@ -233,6 +237,8 @@ int libusb_control_transfer(libusb_device_handle *dev_handle,
uint16_t wLength, uint16_t wLength,
unsigned int timeout) unsigned int timeout)
{ {
int i;
/* Always log the control transfer */ /* Always log the control transfer */
fprintf(dev_handle->packet_data_file, fprintf(dev_handle->packet_data_file,
"%s: RqType: %02x bRequest: %02x wValue: %04x wIndex: %04x timeout: %d\n", "%s: RqType: %02x bRequest: %02x wValue: %04x wIndex: %04x timeout: %d\n",
@ -240,7 +246,7 @@ int libusb_control_transfer(libusb_device_handle *dev_handle,
if (data != NULL) { if (data != NULL) {
fprintf(dev_handle->packet_data_file, "%s: Data[%d]: ", __func__, fprintf(dev_handle->packet_data_file, "%s: Data[%d]: ", __func__,
wLength); wLength);
for (int i = 0; i < wLength; i++) { for (i = 0; i < wLength; i++) {
fprintf(dev_handle->packet_data_file, "%02x ", data[i]); fprintf(dev_handle->packet_data_file, "%02x ", data[i]);
} }
fprintf(dev_handle->packet_data_file, "\n"); fprintf(dev_handle->packet_data_file, "\n");

View File

@ -23,6 +23,7 @@ int main(int argc, char *argv[])
int vid; int vid;
int pid; int pid;
int parsed; int parsed;
int i;
data = fopen(INPUT_DEVICE_LIST_FILE, "w"); data = fopen(INPUT_DEVICE_LIST_FILE, "w");
if (data == NULL) { if (data == NULL) {
@ -32,7 +33,7 @@ int main(int argc, char *argv[])
} }
/* Process arguments until there are fewer than 2 remaining */ /* Process arguments until there are fewer than 2 remaining */
for (int i = 1; i < argc && (argc - i) >= 2; i += 2) { for (i = 1; i < argc && (argc - i) >= 2; i += 2) {
parsed = sscanf(argv[i], "%x", &vid); parsed = sscanf(argv[i], "%x", &vid);
if (parsed != 1) break; if (parsed != 1) break;

View File

@ -73,6 +73,7 @@ int main(int argc, char *argv[])
int index; int index;
int value; int value;
int parsed; int parsed;
int i;
libusb_device_handle *hdl; libusb_device_handle *hdl;
libusb_context *ctx; libusb_context *ctx;
@ -80,7 +81,7 @@ int main(int argc, char *argv[])
ctx = hdl->ctx; ctx = hdl->ctx;
/* Process arguments until there are fewer than 2 remaining */ /* Process arguments until there are fewer than 2 remaining */
for (int i = 1; i < argc && (argc - i) >= 2; i += 2) { for (i = 1; i < argc && (argc - i) >= 2; i += 2) {
parsed = sscanf(argv[i], "%x", &index); parsed = sscanf(argv[i], "%x", &index);
if (parsed != 1) break; if (parsed != 1) break;