News for hackers. Stuff that matters.
Re:Printable True Bugs Wait Posters by thinkpad20 on Friday January 31, 2014 @11:24AM (#7157410)
Do all of your string work with these guys:

    struct string {
      char *str;
      unsigned length;
    }
Re:Printable True Bugs Wait Posters by _telemachus on Friday January 31, 2014 @11:54AM (#7157572)
Let's assume your string struct is solid. Then does that mean you can safely use it with `printf, fprintf, sprintf` (e.g. printf("%s", string->value)? Or must you also write custom versions of those functions? How deep does this rabbit hole go?
Re:Printable True Bugs Wait Posters by thinkpad20 on Friday January 31, 2014 @12:10PM (#7157695)
You don't have to write custom versions of any of those functions; just use the char pointer in the struct instead of a bare char pointer. Keeping track of the length of your strings gives an easy way to provide the 'n' in all of those 'n' functions, and has other advantages besides. But the use of such a struct in and of itself, of course, provides no guarantees of safety. There is no such thing in C anyway :)
Re:Printable True Bugs Wait Posters by dllthomas on Friday January 31, 2014 @03:58PM (#7159141)
You'd probably want

    "%.*s"
or possibly even

    "%*.*s"
if you want it space padded. In principle you can bound your space usage and avoid an snprintf with such constructs; in practice, it's probably better to still use snprintf (if you're using standard-library string functions at all).