"tilt!" <t...@linuxfoo.de> writes:

> Hi Edward,
>
> On 08/25/2015 12:51 PM, Edward Bartolo wrote:
>> [...]
>
> Please accept merge request #1 "cleanup of backend binaries".

Two random remarks:

,----
| size_t essid_safe_strlen(uint8_t * bytes)
| {
|       size_t result;
| 
|       if(!bytes)
|               return 0;
| 
|       result = 0;
| 
|       while(*bytes != 0) {
|               bytes++;
|               result++;
|       }
| 
|       return result; 
| }
`----

A C string of length 0 is just a "\000". A NULL pointer is not a string.
Reimplementing strlen is - apart from that - a rather bizarre idea. A
usual implementation would look somewhat like this:

size_t strlen(char *s)
{
        char *r;

        r = s;
        while (*r) ++r;
        return r - s;
}

ie, it's not necessary to maintain a separate byte counter.

,----
| 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;
}

Considering that this enforces some kind of 'bastard URL-encoding'
(using + as prefix instead of %) for all other bytes, it's also going
make people who believe that UTF-8 would be a well supported way to
represent non-ASCII characters very unhappy.
_______________________________________________
Dng mailing list
Dng@lists.dyne.org
https://mailinglists.dyne.org/cgi-bin/mailman/listinfo/dng

Reply via email to