If an error occurs, the negative return value will be converted to a large positive number. That will probably result in undesired behavior.
src/abycore/util/crypto/crypto.cpp:447:14: warning: comparison of unsigned express ion < 0 is always false [-Wtautological-compare]
if (result < 0) {
~~~~~~ ^ ~
The same thing happens here, read returns a ssize_t.
void gen_secure_random(uint8_t* dest, uint32_t nbytes) {
int32_t randomData = open("/dev/random", O_RDONLY);
uint32_t bytectr = 0;
while (bytectr < nbytes) {
uint32_t result = read(randomData, dest + bytectr, nbytes - bytectr);
if (result < 0) {
cerr << "Unable to read from /dev/random, exiting" << endl;
exit(0);
}
bytectr += result;
}
close(randomData);
}
src/examples/psi_scs/common/sort_compare_shuffle.cpp:320:35: warning: comparison of unsigned expression >= 0 is always true [-Wtautological-compare]
for (k = 0; k < i && j - i - k >= 0; k++) {
~~~~~~~~~ ^ ~
This is in the method
uint64_t Receive(void* pBuf, uint64_t nLen, int nFlags = 0)
.The variable
ret
is declared as unsigned. It used to store the return value ofrecv
.recv
returns a signed value (ssize_t
in POSIX,int
in Winsock), where a negative value represents an error.Since it is assigned to an unsigned variable, the error handling will never be executed:
If an error occurs, the negative return value will be converted to a large positive number. That will probably result in undesired behavior.
The same thing happens here,
read
returns assize_t
.Here is another issue.