From: Marcus M. <ma...@je...> - 2018-12-05 07:10:43
|
Hi, While I applied all others patches, this patch changes other things. Casting between unsigned and signed integers is worse than using incorrect format strings. Perhaps you can use two variables for x, one signed and one unsigned. Ciao, Marcus On Thu, Nov 29, 2018 at 04:59:30PM +0300, Reverend Homer wrote: > [src/ptp.c:568]: (warning) %x in format string (no. 1) requires 'unsigned int *' but the argument type is 'signed int *'. > [src/ptp.c:588]: (warning) %x in format string (no. 1) requires 'unsigned int *' but the argument type is 'signed int *'. > [src/ptp.c:608]: (warning) %x in format string (no. 1) requires 'unsigned int *' but the argument type is 'signed int *'. > [src/ptp.c:620]: (warning) %x in format string (no. 1) requires 'unsigned int *' but the argument type is 'signed int *'. > [src/ptp.c:625]: (warning) %x in format string (no. 1) requires 'unsigned int *' but the argument type is 'signed int *'. > [src/ptp.c:664]: (warning) %x in format string (no. 1) requires 'unsigned int *' but the argument type is 'signed int *'. > [src/ptp.c:675]: (warning) %x in format string (no. 1) requires 'unsigned int *' but the argument type is 'signed int *'. > [src/ptp.c:1108]: (warning) %x in format string (no. 1) requires 'unsigned int *' but the argument type is 'signed int *'. > [src/ptp.c:1114]: (warning) %x in format string (no. 1) requires 'unsigned int *' but the argument type is 'signed int *'. > [src/ptp.c:1962]: (warning) %x in format string (no. 1) requires 'unsigned int *' but the argument type is 'signed int *'. > --- > src/ptp.c | 72 ++++++++++++++++++++++++------------------------------- > 1 file changed, 31 insertions(+), 41 deletions(-) > > diff --git a/src/ptp.c b/src/ptp.c > index d66c8f2..b2bd8bc 100644 > --- a/src/ptp.c > +++ b/src/ptp.c > @@ -552,83 +552,71 @@ parse_9301_cmd_tree (PTPParams *params, xmlNodePtr node, PTPDeviceInfo *di) > static int > parse_9301_value (PTPParams *params, const char *str, uint16_t type, PTPPropertyValue *propval) > { > + unsigned x; > switch (type) { > - case 6: { /*UINT32*/ > - unsigned int x; > + case 6: /*UINT32*/ > if (!sscanf(str,"%08x", &x)) { > ptp_debug( params, "could not parse uint32 %s", str); > return PTP_RC_GeneralError; > } > - ptp_debug( params, "\t%d", x); > + ptp_debug( params, "\t%u", x); > propval->u32 = x; > break; > - } > - case 5: { /*INT32*/ > - int x; > + case 5: /*INT32*/ > if (!sscanf(str,"%08x", &x)) { > ptp_debug( params, "could not parse int32 %s", str); > return PTP_RC_GeneralError; > } > - ptp_debug( params, "\t%d", x); > - propval->i32 = x; > + ptp_debug( params, "\t%u", x); > + propval->i32 = (int32_t)x; > break; > - } > - case 4: { /*UINT16*/ > - unsigned int x; > + case 4: /*UINT16*/ > if (!sscanf(str,"%04x", &x)) { > ptp_debug( params, "could not parse uint16 %s", str); > return PTP_RC_GeneralError; > } > - ptp_debug( params, "\t%d", x); > + ptp_debug( params, "\t%u", x); > propval->u16 = x; > break; > - } > - case 3: { /*INT16*/ > - int x; > + case 3: /*INT16*/ > if (!sscanf(str,"%04x", &x)) { > ptp_debug( params, "could not parse int16 %s", str); > return PTP_RC_GeneralError; > } > - ptp_debug( params, "\t%d", x); > - propval->i16 = x; > + ptp_debug( params, "\t%u", x); > + propval->i16 = (int16_t)x; > break; > - } > - case 2: { /*UINT8*/ > - unsigned int x; > + case 2: /*UINT8*/ > if (!sscanf(str,"%02x", &x)) { > ptp_debug( params, "could not parse uint8 %s", str); > return PTP_RC_GeneralError; > } > - ptp_debug( params, "\t%d", x); > + ptp_debug( params, "\t%u", x); > propval->u8 = x; > break; > - } > - case 1: { /*INT8*/ > - int x; > + case 1: /*INT8*/ > + unsigned int x; > if (!sscanf(str,"%02x", &x)) { > ptp_debug( params, "could not parse int8 %s", str); > return PTP_RC_GeneralError; > } > - ptp_debug( params, "\t%d", x); > + ptp_debug( params, "\t%u", x); > propval->i8 = x; > break; > - } > - case 65535: { /* string */ > - int len; > - > + case 65535: /* string */ > /* ascii ptp string, 1 byte length, little endian 16 bit chars */ > - if (sscanf(str,"%02x", &len)) { > - int i; > - char *xstr = malloc(len+1); > - for (i=0;i<len;i++) { > - int xc; > + if (sscanf(str,"%02x", &x)) { > + unsigned i; > + char *xstr = malloc(x+1); > + for (i=0;i<x;i++) { > + unsigned xc; > if (sscanf(str+2+i*4,"%04x", &xc)) { > int cx; > > cx = ((xc>>8) & 0xff) | ((xc & 0xff) << 8); > xstr[i] = cx; > } > - xstr[len] = 0; > + xstr[x] = 0; > } > ptp_debug( params, "\t%s", xstr); > propval->str = xstr; > @@ -636,7 +624,6 @@ parse_9301_value (PTPParams *params, const char *str, uint16_t type, PTPProperty > } > ptp_debug( params, "string %s not parseable!", str); > return PTP_RC_GeneralError; > - } > case 7: /*INT64*/ > case 8: /*UINT64*/ > case 9: /*INT128*/ > @@ -651,7 +638,7 @@ parse_9301_value (PTPParams *params, const char *str, uint16_t type, PTPProperty > static int > parse_9301_propdesc (PTPParams *params, xmlNodePtr next, PTPDevicePropDesc *dpd) > { > - int type = -1; > + unsigned type = (unsigned)-1; > > if (!next) > return PTP_RC_GeneralError; > @@ -670,7 +657,7 @@ parse_9301_propdesc (PTPParams *params, xmlNodePtr next, PTPDevicePropDesc *dpd) > continue; > } > if (!strcmp((char*)next->name,"attribute")) { /* propdesc.GetSet */ > - int attr; > + unsigned attr; > > if (!sscanf((char*)xmlNodeGetContent (next), "%02x", &attr)) { > ptp_debug( params, "\tattr %s not parseable",xmlNodeGetContent (next)); > @@ -1068,7 +1055,7 @@ ptp_olympus_parse_output_xml(PTPParams* params, char*data, int len, xmlNodePtr * > { > xmlDocPtr docin; > xmlNodePtr docroot, output, next; > - int result, xcode; > + int result; > > *code = NULL; > > @@ -1101,12 +1088,15 @@ ptp_olympus_parse_output_xml(PTPParams* params, char*data, int len, xmlNodePtr * > result = PTP_RC_GeneralError; > > while (next) { > + unsigned xcode; > if (!strcmp((char*)next->name,"result")) { > xmlChar *xchar; > + unsigned ptp_res; > > xchar = xmlNodeGetContent (next); > - if (!sscanf((char*)xchar,"%04x",&result)) > + if (!sscanf((char*)xchar,"%04x",&ptp_res)) > ptp_debug (params, "failed scanning result from %s", xchar); > + result = ptp_res; > ptp_debug (params, "ptp result is 0x%04x", result); > next = xmlNextElementSibling (next); > continue; > @@ -1952,7 +1942,7 @@ ptp_getdevicepropdesc (PTPParams* params, uint16_t propcode, > > ret = ptp_olympus_parse_output_xml (params,(char*)data,size,&code); > if (ret == PTP_RC_OK) { > - int x; > + unsigned x; > > if ( (xmlChildElementCount(code) == 1) && > (!strcmp((char*)code->name,"c1014")) > -- > 2.19.2 > > > > _______________________________________________ > Libmtp-discuss mailing list > Lib...@li... > https://lists.sourceforge.net/lists/listinfo/libmtp-discuss |