Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C Programming > Re: Unitialized Memory Read In sscanf()

Reply
Thread Tools

Re: Unitialized Memory Read In sscanf()

 
 
Eric Sosman
Guest
Posts: n/a
 
      06-24-2003
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).

<off-topic>

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!

</off-topic>

--
http://www.velocityreviews.com/forums/(E-Mail Removed)
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Ruport::DataSet unitialized constant? Michael Linfield Ruby 1 08-15-2007 10:41 PM
Detection of unitialized member variables toddel@gmail.com C++ 2 10-24-2005 07:14 PM
using % operator to print possibly unitialized data attributes Adam Monsen Python 3 09-09-2005 10:40 PM
Unitialized pointers? Greg C Programming 5 10-11-2004 01:20 AM
Re: Unitialized Memory Read In sscanf() Darrell Grainger C Programming 1 06-24-2003 06:52 PM



Advertisments