Gregory Stark <stark@xxxxxxxxxxxxxxxx> writes: > Teodor Sigaev <teodor@xxxxxxxxx> writes: > >> I reproduced the bug with a help of Grzegorz's point for 64-bit box. So, patch >> is attached and I'm going to commit it > ... > >> ! Conf->flagval[(unsigned int) *s] = (unsigned char) val; > ... >> ! Conf->flagval[*(unsigned char*) s] = (unsigned char) val; > > Maybe I'm missing something but I don't understand how this fixes the problem. Ah, I understand how this fixes the problem. You were casting to unsigned *int* not unsigned char so it was sign extending first and then overflowing. So char<255> was coming out as MAX_INT instead of 255. #include <stdio.h> main() { volatile signed char a = -1; printf("ud=%ud\n", (unsigned int)a); } $ ./a.out ud=4294967295d If you just make these all casts to (unsigned char) it should work just as well as the pointer type punning -- and be a whole lot less scary. > What really boggles me is why you don't just use unsigned chars everywhere and > remove all of these casts. or would that just move the casts to strcmp and > company? It still seems to me if you put a few "unsigned" in variable declarations you could remove piles upon piles of casts and make all of the code more readable. -- Gregory Stark EnterpriseDB http://www.enterprisedb.com Ask me about EnterpriseDB's 24x7 Postgres support! -- Sent via pgsql-general mailing list (pgsql-general@xxxxxxxxxxxxxx) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-general