Uhm... why the convolusion?

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

Uhm... why the convolusion?

Peter J. Philipp
88% down on crypt.c in /usr/src/lib/libc/crypt/crypt.c is the following...

        while ((q - (u_char *) keybuf) < sizeof(keybuf)) {
                if ((*q++ = *key << 1))
                        key++;

The if statement is just irrelevant, why is this convoluted?  Can I get my
mind around this please?

low disregards,

-peter

--
Here my ticker tape .signature #### My name is Peter Philipp #### lynx -dump "http://en.wikipedia.org/w/index.php?title=Pufferfish&oldid=20768394" | sed -n 131,136p #### http://centroid.eu #### So long and thanks for all the fish!!!

Reply | Threaded
Open this post in threaded view
|

Re: Uhm... why the convolusion?

Daniel Hartmeier
On Fri, Sep 22, 2006 at 12:42:49PM +0200, Peter Philipp wrote:

> 88% down on crypt.c in /usr/src/lib/libc/crypt/crypt.c is the following...
>
>         while ((q - (u_char *) keybuf) < sizeof(keybuf)) {
>                 if ((*q++ = *key << 1))
>                         key++;
>
> The if statement is just irrelevant, why is this convoluted?  Can I get my
> mind around this please?

Why didn't you quote the comment that is found just above those lines?
It's actually helpful:

        /*
         * Copy the key, shifting each character up by one bit
         * and padding with zeros.
         */

The key is a NUL-terminated string. The while loop ensures that every
byte of keybuf gets written to. Once it reaches the end of key (where
*key == 0, the NUL terminator), it stops advancing key, but continues to
write to keybuf (writing the same NUL byte as long as needed). That's
what the comment means with 'padding with zeros', it applies when key is
shorter than sizeof(keybuf), i.e. less than 8 characters.

Daniel

Reply | Threaded
Open this post in threaded view
|

Re: Uhm... why the convolusion?

Peter J. Philipp
On Fri, Sep 22, 2006 at 01:01:52PM +0200, Daniel Hartmeier wrote:

> On Fri, Sep 22, 2006 at 12:42:49PM +0200, Peter Philipp wrote:
>
> > 88% down on crypt.c in /usr/src/lib/libc/crypt/crypt.c is the following...
> >
> >         while ((q - (u_char *) keybuf) < sizeof(keybuf)) {
> >                 if ((*q++ = *key << 1))
> >                         key++;
> >
> > The if statement is just irrelevant, why is this convoluted?  Can I get my
> > mind around this please?
>
> Why didn't you quote the comment that is found just above those lines?
> It's actually helpful:
>
>         /*
>          * Copy the key, shifting each character up by one bit
>          * and padding with zeros.
>          */
>
> The key is a NUL-terminated string. The while loop ensures that every
> byte of keybuf gets written to. Once it reaches the end of key (where
> *key == 0, the NUL terminator), it stops advancing key, but continues to
> write to keybuf (writing the same NUL byte as long as needed). That's
> what the comment means with 'padding with zeros', it applies when key is
> shorter than sizeof(keybuf), i.e. less than 8 characters.
>
> Daniel

I get the logic now.  Thanks Daniel.  

-p

--
Here my ticker tape .signature #### My name is Peter Philipp #### lynx -dump "http://en.wikipedia.org/w/index.php?title=Pufferfish&oldid=20768394" | sed -n 131,136p #### http://centroid.eu #### So long and thanks for all the fish!!!