Re: strlen
On 7 Sep 2007 22:46:23 GMT, richard@cogsci. ed.ac.uk (Richard Tobin)
wrote:
no i like to arguing with myself in public
your is a not valid signature
On Mon, 03 Sep 2007 21:24:38 -0000,(Gordon Burditt) wrote:
>
>strlen() has no way to report errors, according to its definition
>in Standard C.
strlen has a way to report error because the string
a[strlen(a)];
not exist if strlen(a)=size_ tmax
|""| = 0 len, 1 size
|"a"| = 1 len, 2 size
.............
and not exist
|"..."| = size_tmax len, (size_tmax +1) size
so strlen() can return only <=(size_tmax -1)
so size_tmax is for error
is it above correct?
wrong for above
see above: strlen return size_tmax
>
>That's not what Standard C says.
:)))
>
>It can either return or not continue to run; it can't do both.
yes it has to return and not hang the program with the infinite loop
but possibly i have seen wrong on it
>
>That's not what Standard C says. And there's a difference between
>shutting down the *program* (e.g. with smegmentation fault), and
>shutting down the *system* (e.g. with blue screen of death or panic:
>out of swap space).
if your program is an OS program it can shut down the system
>
>
>I'd be interested in how functions like exit() and abort() report errors,
>and how a programmer checks for errors.
i don't know, i say that it is better that every function return in
some way if the operation goes well
or all data has some flag that say if all operations with that data
are all ok
On 7 Sep 2007 22:46:23 GMT, richard@cogsci. ed.ac.uk (Richard Tobin)
wrote:
>In article <98i3e3tg83l6m7 r18cmmd69pc4448 fpqom@4ax.com>, ¬a\\/b <al@f.gwrote:
>
>Perhaps you'd like to try arguing with yourself in private?
>>On Fri, 07 Sep 2007 23:52:48 +0200, "¬a\\/b" <al@f.gwrote:
>>
>>wrong etc
>>>On Fri, 07 Sep 2007 23:49:45 +0200, "¬a\\/b" <al@f.gwrote:
>>>>On Mon, 03 Sep 2007 21:24:38 -0000,(Gordon Burditt) wrote:
>>>>>>>strlen is wrong because can not report if there is some error
>>>>>
>>>>>strlen() has no way to report errors, according to its definition
>>>>>in Standard C.
>>>>
>>>>strlen has a way to report error because the string
>>>
>>>strlen() has no way to report errors,
>>>>On Mon, 03 Sep 2007 21:24:38 -0000,(Gordon Burditt) wrote:
>>>>>>>strlen is wrong because can not report if there is some error
>>>>>
>>>>>strlen() has no way to report errors, according to its definition
>>>>>in Standard C.
>>>>
>>>>strlen has a way to report error because the string
>>>
>>>strlen() has no way to report errors,
>>wrong etc
>Perhaps you'd like to try arguing with yourself in private?
>-- Richard
On Mon, 03 Sep 2007 21:24:38 -0000,(Gordon Burditt) wrote:
>>>strlen is wrong because can not report if there is some error
>strlen() has no way to report errors, according to its definition
>in Standard C.
a[strlen(a)];
not exist if strlen(a)=size_ tmax
|""| = 0 len, 1 size
|"a"| = 1 len, 2 size
.............
and not exist
|"..."| = size_tmax len, (size_tmax +1) size
so strlen() can return only <=(size_tmax -1)
so size_tmax is for error
is it above correct?
>strlen() may well have no way to *detect* the error of an unterminated
>string without causing undefined behavior
>string without causing undefined behavior
>(aborting the program with
>a smegmentation fault, for example. And nobody said a smegmentation
>fault has to be a catchable error).
>
>>
>>you have right only if the programmer never make errors
>>are you a programmer of that kind?
>
>How does one *detect* such an error? Especially if a + size_t max is
>off the end of allocated memory?
>a smegmentation fault, for example. And nobody said a smegmentation
>fault has to be a catchable error).
>
>>>e.g.
>>>char *a;
>>>and "a" point to an array of size=size_t max that has no 0 in it
>>>
>>>strlen is defined on strings. A string has a 0 char terminating it. It
>>>is not strlen that is wrong but the incompetent programmer.
>>>char *a;
>>>and "a" point to an array of size=size_t max that has no 0 in it
>>>
>>>strlen is defined on strings. A string has a 0 char terminating it. It
>>>is not strlen that is wrong but the incompetent programmer.
>>you have right only if the programmer never make errors
>>are you a programmer of that kind?
>How does one *detect* such an error? Especially if a + size_t max is
>off the end of allocated memory?
>>if strlen sees some problem it has to report an error
>That's not what Standard C says.
>>example return (size_t)-1 and not continue to run
>It can either return or not continue to run; it can't do both.
but possibly i have seen wrong on it
>>if there is strlen(0); it has to report the error and not shut down
>>the system
>>the system
>That's not what Standard C says. And there's a difference between
>shutting down the *program* (e.g. with smegmentation fault), and
>shutting down the *system* (e.g. with blue screen of death or panic:
>out of swap space).
>>So if i want to hang some of your pragrams i have just give a string
>>of size_t max len that has 111111111111111 111111111111111 1111111111
>>etc in it because for these string, there is the chance strlen should
>>result in an infinite loop (or ggets or fgets or what you want).
>>of size_t max len that has 111111111111111 111111111111111 1111111111
>>etc in it because for these string, there is the chance strlen should
>>result in an infinite loop (or ggets or fgets or what you want).
>>the idea is *all* functions should can to report errors if they see
>>these errors (and the programmer has to see if something goes wrong
>>until it is printf)
>>these errors (and the programmer has to see if something goes wrong
>>until it is printf)
>I'd be interested in how functions like exit() and abort() report errors,
>and how a programmer checks for errors.
some way if the operation goes well
or all data has some flag that say if all operations with that data
are all ok
Comment