Valgrind error "Conditional jump or move depends on uninitialised value" on 64-bit

[Sending this directly to you because POSTing it on website does not seem to be working for me. This is about reproducing valgrind issue and a compilation warning.] Arthur and Paul, I'm seeing two problems in localtime.c: 1. When I compile localtime.c using gcc 4.1.2 for 32-bit, I get following warning: $ gcc -m32 -g -c -o localtime.o localtime.c localtime.c: In function âdiffer_by_repeatâ: localtime.c:326: warning: comparison is always false due to limited range of data type 2. valgrind reports following error for some timezones (only when localtime.c is compiled as 64-bit binary, it does not happen when compiled as 32-bit binary): ==26671== Conditional jump or move depends on uninitialised value(s) ==26671== at 0x401CDA: typesequiv (localtime.c:588) ==26671== by 0x401B85: tzload (localtime.c:562) ==26671== by 0x405553: tz_validate (localtime.c:2017) ==26671== by 0x40560D: main (localtime.c:2040) One can reproduce it using following valgrind command and patch: valgrind -v --tool=memcheck --leak-check=full --leak-resolution=med --show-reachable=yes --error-limit=no --workaround-gcc296-bugs=yes --run-libc-freeres=no --log-file=valgrind-tzvalid ./tzvalid /<path/to/my/zoneinfo/EST5EDT> NOTE: I can consistently reproduce it for EST5EDT timezone and I don't get this error for GMT. Patch for localtime.c for reproducing above error: --- org/localtime.c 2010-08-16 16:27:05.000000000 +0530 +++ localtime.c 2010-10-01 17:34:45.999089000 +0530 @@ -2004,6 +2004,47 @@ #endif /* defined CMUCS */ +static int +tz_validate(const char * name) +{ + struct state state = {0}; + time_t now; + struct tm tm; + + time(&now); + tzload(gmt, &state, TRUE); + if (0 == tzload(name, &state, TRUE)) { + localsub(&now, 0L, &tm); + return TRUE; + } + if (0 == tzparse(name, &state, FALSE)) { + localsub(&now, 0L, &tm); + return TRUE; + } + return FALSE; +} + +/* + * Compile it simply as "$gcc -m64 -g -o tzvalid localtime.c" + */ +int main(int argc, char ** argv) { + + if (argc != 2) { + printf("Usage: ./tzvalid <timezone_file_path>\n"); + return 2; + } + + char * tz = argv[1]; + + if (tz_validate(tz)) { + printf("timezone %s is valid\n", tz); + return 0; + } else { + printf("timezone %s is not valid\n", tz); + return 1; + } +} + /* ** XXX--is the below the right way to conditionalize?? */ Thanks in advance, Ravindra
participants (1)
-
Ravindra