home bbs files messages ]

Forums before death by AOL, social media and spammers... "We can't have nice things"

   alt.unix.geeks      The gathering of the socially-retarded      298 messages   

[   << oldest   |   < older   |   list   |   newer >   |   newest >>   ]

   Message 230 of 298   
   Richard Kettlewell to Scott Lurndal   
   Re: What is wrong with C? (and fond memo   
   06 Jan 26 22:54:26   
   
   XPost: comp.os.linux.misc, alt.folklore.computers   
   From: invalid@invalid.invalid   
      
   scott@slp53.sl.home (Scott Lurndal) writes:   
   > rbowman  writes:   
   >>On Tue, 06 Jan 2026 18:57:04 GMT, Charlie Gibbs wrote:   
   >>> Inspired by readline(), I've written my own replacements for strcpy()   
   >>> and strcat() that do much the same thing.   
   >>   
   >>To quote from the strcat man page "Read about Shlemiel the painter.".   
   >>stpcpy() was a late arrival and I never used it. I do use a similar   
   >>construct   
   >>   
   >>char buf[1024];   
   >>char* ptr = buf;   
   >>   
   >>ptr += sprintf(ptr, "%s", "some stuff");   
   >>ptr += sprintf(ptr, "%s", " some more stuff");   
   >   
   > I would suggest using snprintf instead of sprintf   
   > to prevent accesses beyond (buf + 1024).  A bit   
   > more complicated if you want to know that the   
   > result was truncated, since you need to adjust the   
   > remaining length based on the return value from   
   > the prior snprintf, as well as checking for   
   > overflow.   
      
   This is calling out for a wrapping up in a function or two that can do   
   the book-keeping automatically (and use an expandable buffer, if the use   
   case demands).   
      
   --   
   https://www.greenend.org.uk/rjk/   
      
   --- SoupGate-Win32 v1.05   
    * Origin: you cannot sedate... all the things you hate (1:229/2)   

[   << oldest   |   < older   |   list   |   newer >   |   newest >>   ]


(c) 1994,  bbs@darkrealms.ca