Re: Writing bulletproof code

From: Programmer Dude (Chris_at_Sonnack.com)
Date: 01/06/04


Date: Tue, 06 Jan 2004 12:19:20 -0600


"Arthur J. O'Dwyer" wrote:

I guess my question is...

> If I want to write a function in C that takes a user-id
> as a parameter, I not only have to check that the string is
>
> 1) not empty
> and 2) well-formed
>
> but also, because of the form of the language, I must check that
> it is
>
> 3) not a null pointer
>
> and *also*, because of the lack of "check-ability," I am *unable*
> to check that it is
>
> 4) a null-terminated string
> 5) not a wild pointer
> 6) not a floating-point value reinterpreted as a string
> 7) not a pointer to a value that may change at whim
>
> ...and so on.

...what are the relative chances of the above errors? IME, as
initializing to NULL, or using NULL as an error return value, is
very common, erroneously receiving a NULL pointer has a fairly
high likelihood.

Thus, IMO, it is reasonable to check for.

-- 
|_ CJSonnack <Chris@Sonnack.com> _____________| How's my programming? |
|_ http://www.Sonnack.com/ ___________________| Call: 1-800-DEV-NULL  |
|_____________________________________________|_______________________|


Relevant Pages

  • Re: "Mastering C Pointers"....
    ... A pointer is a kind of variable that can "point to" some object. ... has a type (pointer to int), and a value of some kind. ... You may know that you can access these integers by using array notation ... The function will take one argument, a string, and will return the length ...
    (comp.lang.c)
  • Re: pesky Pointers !!
    ... > and the function takes it as a reference instead of a copy. ... function may access the string passed directly, ... > *px dereferences the pointer to get the value ... If pTest is a pointer-to-string, *pTest is the string it points to ...
    (alt.comp.lang.learn.c-cpp)
  • Re: strtok ( ) help
    ... > splitCommandssomehow modifying the pointer, but I HAVE to call that ... Here's an idea of how to use the strtok() function. ... don't mind trashing the contents of a string s, ... will give you a loop that extracts the tokens one at a time from s. ...
    (comp.lang.c)
  • Re: new IL: C (sort of...).
    ... C doesn't need a string type... ... variant of PL/1 which was very Pascal-ish. ... - C does implement an array declaration. ... effectively converted into a pointer that can be used with the offset ...
    (comp.lang.misc)
  • Re: copy a string into a 2d array of chars
    ... This split function should allocate a 2D array of chars ... >focus the program the string is not actually split. ... later) is an array of char containing the original contents of the ... The i-th pointer will contain the starting address of the ...
    (comp.lang.c)