tolower trick in net.c

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

tolower trick in net.c

Jeffrey Walton-3
Hi Everyone,

I was looking at
https://git.savannah.gnu.org/cgit/hurd/gnumach.git/tree/xen/net.c. The
tolower trick of setting the 5th bit is not portable. C does not
guarantee the trick.

    for (number = 0, c = *cp | 0x20; ... )

As far as I know the only guarantees are:

* letters A-Z and a-z exist and that they fit within a byte
* digits 0-9 are sequential

It may be a good idea to just call tolower on *cp.

Jeff

Reply | Threaded
Open this post in threaded view
|

Re: tolower trick in net.c

Samuel Thibault-8
Hello,

Jeffrey Walton, le lun. 12 août 2019 22:59:56 -0400, a ecrit:
> The tolower trick of setting the 5th bit is not portable. C does not
> guarantee the trick.
>
>     for (number = 0, c = *cp | 0x20; ... )

Indeed, but GNU Mach does talk ASCII, it's not planned to use some other
encoding any day.

> It may be a good idea to just call tolower on *cp.

We do not have 'tolower' inside the kernel.
(and if we had, it would use the 5th bit trick :) )

Samuel