Subj : Re: Codeguard found error in sprintf() To : borland.public.cpp.borlandcpp From : "Ed Mulroy [TeamB]" Date : Wed Feb 25 2004 09:12 am I think Codeguard is interpreting the "%25s" format string and reporting that r is not 25 char's long. It is not looking inside of sprintf but rather at the calling arguments. Codeguard is a tool, not perfect, but useful. It tries to capture a wide ranging set of errors at the risk of occasionally showing an oddball errror that isn't true. The alternative is to trim it down but then it would find less in the way of true errors and you probably don't want that. .. Ed > Richard Hufford wrote in message > news:403bf772@newsgroups.borland.com... > > I've just started using Codeguard to look for errors in my > BC++ 5.01 program, and it found an error in one of my > common uses of sprintf(). My code looks much like this: > > char buf[100]; > char *r = new char[8]; > strcpy (r, "richard"); > sprintf (buf, "%25s", r); > > Codeguard gives this message: > CodeGuard Error: Access overrun (thread 0x0114) > Attempt to access 25 byte(s) at 0x014C63B4, that is at > heap block 0x014C63B4 which is only 8 bytes long. > > Apparently, sprintf tries to access 25 characters pointed > to by r. I assume sprintf is trying to read these characters, > not write them, so this is not really a problem. Am I correct? .