[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Chicken-users] valgrind - more details

From: Jörg F . Wittenberger
Subject: Re: [Chicken-users] valgrind - more details
Date: 05 Oct 2011 22:29:07 +0200

On Oct 5 2011, Jörg F. Wittenberger wrote:

==13112== Conditional jump or move depends on uninitialised value(s) ==13112== at 0x510393E: C_a_i_string_to_number (in

While I've been following this valgrind hint I ran into some
code in C_a_i_string_to_number ... as expectable this code
is kinda complicated since the problem it solves is just below
the level where one would consider to write a real parser and
at the same time beyond complexity you want to handle ad hoc.

To reduce my confusion, I allowed myself to make some changes,
even if those where just for me to make clear what the code
tries to do.

I found two occurrences of strlen (C_strlen that is), which would
for no good reason scan the memory while the result could be computed
by simple pointer arithmetic:

@@ -7519,19 +7515,19 @@
    errno = 0;
    fn = C_strtod(str, &eptr2);

    if(fn == HUGE_VAL && errno == ERANGE) return 0;
else if(eptr2 == str) return 0; - else if(*eptr2 == '\0' || (eptr != eptr2 && !C_strncmp(eptr2, ".0", C_strlen(eptr2)))) { + else if(*eptr2 == '\0' || (eptr != eptr2 && !C_strncmp(eptr2, ".0", len - (eptr2-str)))) {
      *flo = fn;
      return 2;

    return 0;
else if((n & C_INT_SIGN_BIT) != ((n << 1) & C_INT_SIGN_BIT)) { /* doesn't fit into fixnum? */ - if(*eptr == '\0' || !C_strncmp(eptr, ".0", C_strlen(eptr))) { + if(*eptr == '\0' || !C_strncmp(eptr, ".0", len - (eptr-str))) {
      *flo = (double)n;
      return 2;
    else return 0;

The there is one thing which looks like a typo to me:

@@ -7505,11 +7501,11 @@
        return 0;

-  if(C_strpbrk(str, "xX\0") != NULL) return 0;
+  if(C_strpbrk(str, "xX") != NULL) return 0;

  errno = 0;
  n = C_strtol(str, &eptr, radix);

if(((n == LONG_MAX || n == LONG_MIN) && errno == ERANGE) || *eptr != '\0') {

And a few spots, where the goto-dance was too confusion.
(Full diff attached.)

The sad news: while this might help to make the source better,
it's for acaemic reason.  So far the problem is the same

valgrind --log-file=/tmp/ --track-origins=yes csi -e "(display (length '( n01 n02 n03 n04 n05 n06 n07 n08 n09 n10 n11 n12 n13 n14 n15 n16 n17 n18 n19 n20 n21 n22 n23 n24 n25 n26 n27 n28 n29 n30 n31 n32 n33 n34 n35 n36 n37 n38 n39 n40 n41 n42)))"

will print 42 and exit with a clean valgrind report.

valgrind --log-file=/tmp/ --track-origins=yes csi -e 42

however will complain about access to uninitialised values.


I'll shut up on this topic (which looks probably boring)
once I either know that there is a known reason or someone taking
care of it (or helps me to do so).  Until then I better keep you
informed, since I'm afraid it will come up again.

Attachment: cleanup.diff
Description: cleanup.diff

reply via email to

[Prev in Thread] Current Thread [Next in Thread]