Re: Unitialized Memory Read In sscanf()

Discussion in 'C Programming' started by Eric Sosman, Jun 24, 2003.

  1. Eric Sosman

    Eric Sosman Guest

    Keith wrote:
    > When running purify on the following program:
    > #include <stdio.h>
    > int main() {
    > int my_int ;
    > char buf[3] ;
    > strcpy(buf, "12" ) ;
    > sscanf( buf, "%d", &my_int ) ;
    > }
    > I get a UMR on the sscanf() when using purify. This is on an IRIX machine.
    > Any suggestions?

    As far as I can tell, there's nothing seriously wrong
    with your C. (Others have mentioned the lack of <string.h>
    and of a return, but I'd be astonished if either of those
    led to the symptom you report. You can certainly make the
    corrections and see whether the problem persists.) So: if
    the problem isn't with the C code, it must be with the tool
    or with the implementation, and you should seek help not from
    the C language pedants, but from the IRIX and Purify gurus
    (wherever they may reside).


    A wild guess: Maybe the string functions underpinning
    sscanf() -- strlen(), strchr(), perhaps others -- try to
    optimize memory accesses, fetching several bytes at once
    instead of walking through the string byte by byte. If so,
    it might well be that such functions fetch more than three
    bytes from `buf', detecting the '\0' terminator before doing
    anything with the extra bytes. This is harmless in actual
    fact (if the implementation handles the details), but Purify
    may detect the beyond-the-end fetches, see that the extra
    bytes have never been initialized (make a few suppositions
    about the stack layout, okay?), and squawk. IF this is
    the case, you might also see the same symptom by replacing
    the sscanf() with calls to strlen(), strchr(), and so on.
    And IF this is the case, it's likely the Purify people know
    about it and have a way to silence the bogus warning -- maybe
    a substitute string library or something. Good luck!


    Eric Sosman, Jun 24, 2003
    1. Advertisements

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Darrell Grainger

    Re: Unitialized Memory Read In sscanf()

    Darrell Grainger, Jun 24, 2003, in forum: C Programming
    Alan Balmer
    Jun 24, 2003
  2. Adam Monsen
    =?iso-8859-1?Q?Fran=E7ois?= Pinard
    Sep 9, 2005
  3. Greg

    Unitialized pointers?

    Greg, Oct 11, 2004, in forum: C Programming
  4. Replies:
  5. Michael Linfield

    Ruport::DataSet unitialized constant?

    Michael Linfield, Aug 15, 2007, in forum: Ruby
    Stefan Mahlitz
    Aug 15, 2007

Share This Page