liteserver / binn

Binary Serialization
Apache License 2.0
440 stars 58 forks source link

Compilation warnings #5

Closed mannol closed 5 years ago

mannol commented 7 years ago

There variables are "maybe uninitialized" in these contexts. Nice lib btw!

binn.c: In function ‘copy_int_value’: binn.c:2123:21: warning: ‘vint64’ may be used uninitialized in this function [-Wmaybe-uninitialized] (int )pdest = (int) vint64; ^~~~ binn.c:2139:30: warning: ‘vuint64’ may be used uninitialized in this function [-Wmaybe-uninitialized] (unsigned int )pdest = (unsigned int) vuint64; ^~~~~~ binn.c: In function ‘AddValue’: binn.c:717:6: warning: ‘vint’ may be used uninitialized in this function [-Wmaybe-uninitialized] if (vint >= INT32_MIN) { ^ binn.c:669:10: note: ‘vint’ was declared here int64 vint;

ghost commented 5 years ago

Here is an update,

I tried this on gcc 5.4.0 and it only seems to occur with speed optimizations turned on e.g -O1/-O2/-O3.

I skimmed through binn.c and it probably won't hurt to initialize these variables to 0 (zero) to get rid of the compiler warnings.

Fix: Init vuint64 = 0; @ line 2157 Fix: Init vint64 = 0; @ line 2157 Fix: Init vint = 0; @ line 730 Fix: Init len = 0; @ line 1572 Fix: Init id = 0; @ line 1571 Fix: Init key = NULL; @ 1572


binn.c: In function ‘copy_int_value’: binn.c:2213:21: warning: ‘vint64’ may be used uninitialized in this function [-Wmaybe-uninitialized] (int )pdest = (int) vint64; ^ binn.c:2229:30: warning: ‘vuint64’ may be used uninitialized in this function [-Wmaybe-uninitialized] (unsigned int )pdest = (unsigned int) vuint64; ^ binn.c: In function ‘AddValue’: binn.c:778:6: warning: ‘vint’ may be used uninitialized in this function [-Wmaybe-uninitialized] if (vint >= INT32_MIN) { ^ binn.c:730:10: note: ‘vint’ was declared here int64 vint; ^ binn.c: In function ‘binn_read_pair’: binn.c:1619:9: warning: ‘len’ may be used uninitialized in this function [-Wmaybe-uninitialized] memcpy(pkey, key, len); ^ binn.c:1615:21: warning: ‘id’ may be used uninitialized in this function [-Wmaybe-uninitialized] if (pid) *pid = id;

src/binn.c: In function ‘binn_read_pair’: src/binn.c:1619:9: warning: ‘key’ may be used uninitialized in this function [-Wmaybe-uninitialized] memcpy(pkey, key, len);

kroggen commented 5 years ago

Hi!

I am without spare time now, with lots of work.

Do you want to send a pull request?

ghost commented 5 years ago

Ok. I am kind of new to git so please tell me if I am doing something wrong here. I have forked binn, updated binn.c, and made a pull request. Is this correct?

kroggen commented 5 years ago

Yes.

Your pull request was merged.

Thank you for your contribution!

ghost commented 5 years ago

Good. Happy to help!