Search code examples
csoapuigsoap

When i am trying to migrate my code from 32 to 64 bit , Gsoap gives me warnings related to -Wsign-conversion, how to resolve this warnings?


Gsoap gives me warnings related to -Wsign-conversion, since gsoap source files are auto generated i am unable to resolve these warnings. Can someone please me with this. Thanks in advance.

64bit Warnings example

warning: conversion to long unsigned int from int may change the sign of the result [-Wsign-conversion]
char *a = (char*)soap_malloc((soap), (n = (n < 0 ? 1 : n)) * sizeof(char));

32bit warnings example warning: conversion to unsigned int from int may change the sign of the result [-Wsign-conversion]
char *a = (char*)soap_malloc((soap), (n = (n < 0 ? 1 : n)) * sizeof(char));

I went through their document but not much help in that regarding above warnings.


Solution

  • Ignore the warning. It's generated code, you cannot change it.

    However, you can easily see that it is a false positive: The test n = (n < 0 ? 1 : n) specifically guarantees that the number is positive before the conversion; all negative numbers become 1.

    There is no danger here in converting a signed 32 or 64 bit int to its unsigned equivalent when the signed value is guaranteed to be positive.