:: Re: [DNG] netman GIT project
トップ ページ
このメッセージを削除
このメッセージに返信
著者: Hendrik Boom
日付:  
To: dng
題目: Re: [DNG] netman GIT project
On Tue, Aug 25, 2015 at 01:09:27PM +0100, Rainer Weikusat wrote:
> "tilt!" <tilt@???> 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.


The Korean encoding before UTF-8 used two-byte characters. Sone of
those characters contained zero bytes as parts of a two-byte nonzero
encoding.

I had to use environment-dependent string copying to get that one right.

-- hendrik

> _______________________________________________
> Dng mailing list
> Dng@???
> https://mailinglists.dyne.org/cgi-bin/mailman/listinfo/dng