:: Re: [DNG] netman GIT project
Página Inicial
Delete this message
Reply to this message
Autor: Irrwahn
Data:  
Para: dng
Assunto: Re: [DNG] netman GIT project
On Tue, 25 Aug 2015 13:09:27 +0100, Rainer Weikusat wrote:
<snip>
> ,----
> | uint8_t essid_allowed_chars[] = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789-";
> | 
> | [...]
> | 
> | int essid_allowed_char(uint8_t c) {
> |     size_t i;
> |     size_t k;
> | 
> |     int rv;
> | 
> |     rv = 0;
> | 
> |     k = essid_safe_strlen(essid_allowed_chars);
> | 
> |     for (i=0; i<k; i++)
> |         if(c==essid_allowed_chars[i]) {
> |             rv = 1;
> | 
> |             break;
> |         }
> | 
> |     return rv;
> | }
> `----

>
> A more sensible simple way to implement this would be
>
> char *essid_allowed_chars = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789-";
>
> int essid_allowed_char(int c)
> {
>     return strchr(essid_allowed_chars, c) != NULL;
> }

<snip>

One minor nitpick, SCNR:
To exactly replicate the behavior that last line should read:

return c && ( strchr(essid_allowed_chars, c) != NULL );

or simply:

return c && strchr(essid_allowed_chars, c);

Rationale: strchr considers the terminating null character to be
part of the string, whereas the original code does not. (Not that
it would matter yet, given how the function is currently used in
the context of the original code, but it's the kind of thing that
tends to bite later on.)

--
Irrwahn