Re: Are bad developer libraries the problem with M$ software?

From: Casper Dik (Casper.Dik@Sun.COM)
Date: 11/18/02

  • Next message: Michael Howard: "RE: Are bad developer libraries the problem with M$ software?"
    To: Frank Knobbe <fknobbe@knobbeits.com>
    Date: Mon, 18 Nov 2002 20:36:33 +0100
    From: Casper Dik <Casper.Dik@Sun.COM>
    

    >As a side note, proper use of snprintf would be:
    >ret = snprintf(mystr,sizeof(mystr)-1,"Format: %s",var);

    No it would not; the proper 2nd argument is the size of whatever
    "mystr" points to; for char[] that's sizeof (mystr) (NOT -1) but
    for char * it's whatever size you alloc'ed.

    >Perhaps we should start development of a standardized 'safe' header file
    >that can contain macros for snprintf, strncat and the like.
    >
    >Example:
    >#define safe_snprinf(dst,len,fmt,var)
    > snprintf(dst,(len>sizeof(dst)-1)?sizeof(dst)-1:len,fmt,var)

    I remember a bug in sendmail caused by bad use of sizef.

    >#define safe_strcat(dst,src) =20
    > strncat(dst,src,sizeof(dst))

    Same problem; not safe anyway. (sizeof (dst) - strlen(dst) - 1, if anything)

    Casper



    Relevant Pages

    • Re: Reading program output from stdin
      ... > haven't even got a proper char buffer to pass to the string functions, ... > but something vague called a String. ... And of course it is not a "proper" string but a length ...
      (comp.lang.c)
    • Re: How to write Unicode
      ... printStream.print((char)0x000A); ... If you're trying to get from a Java String to UTF-8 bytes, ... converting for you. ...
      (comp.lang.java.programmer)
    • Fast Title Case (Was Re: Could someone figure out why the below code
      ... If we use a single bit to determine if a char is a word/non-word char, and remember the last two chars, we get the following states: ... We therefore generate two consecutive 512-byte tables, each consisting of 256 16-bit entries: The bottom 8 bits is the proper case conversion, while the 10th bit indicates word/non-word, which will be used to select the proper half of the table to be used! ... Start in outside word mode, so first word char needs uppercase: ...
      (comp.lang.asm.x86)
    • Re: Fast Title Case (Was Re: Could someone figure out why the below code
      ... If we use a single bit to determine if a char is a word/non-word char, ... one could use the table for uppercase when there is 1 in the result of xor ... which will be used to select the proper half ...
      (comp.lang.asm.x86)
    • Re: (char *)0 vs NULL
      ... Casper H.S. Dik wrote: ... char *t; ... int i = 0; ...
      (comp.unix.programmer)