Velocity Reviews

Velocity Reviews (http://www.velocityreviews.com/forums/index.php)
-   C Programming (http://www.velocityreviews.com/forums/f42-c-programming.html)
-   -   Re: Unitialized Memory Read In sscanf() (http://www.velocityreviews.com/forums/t313786-re-unitialized-memory-read-in-sscanf.html)

Eric Sosman 06-24-2003 08:03 PM

Re: Unitialized Memory Read In sscanf()
 
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>

--
Eric.Sosman@sun.com


All times are GMT. The time now is 06:06 AM.

Powered by vBulletin®. Copyright ©2000 - 2014, vBulletin Solutions, Inc.
SEO by vBSEO ©2010, Crawlability, Inc.