[erlang-bugs] fmtq bug by inspection

Edwin Fine erlang-questions_efine@REDACTED
Tue Jun 17 15:00:01 CEST 2008


I think you are right, because the following line *requires* that *ptr be
between '0' and '7'. It appears that this code is packing an octal
representation of an ASCII digit into 3 bits.

 c = (c << 3) | (*ptr - '0');

On Mon, Jun 16, 2008 at 4:12 PM, Perry Smith <pedzsan@REDACTED> wrote:

> This looks like a bug to me:
>
> static char* fmtq(char* ptr, int* buf)
> {
>     int c;
>
>     switch((c=*ptr++)) {
> <snip>
>     case '0': case '1': case '2': case '3': case '4':
>     case '5': case '6': case '7':
>        c = c - '0';
>        if ((*ptr >= 0) && (*ptr <= 7)) { <<<<<
>            c = (c << 3) | (*ptr - '0');
>            ptr++;
>            if ((*ptr >= 0) && (*ptr <= 7)) { <<<<<
>                c = (c << 3) | (*ptr - '0');
>                ptr++;
>            }
>        }
>        break;
>     }
>     *buf = c;
>     return ptr;
> }
>
> Shouldn't it be:
>
>     case '0': case '1': case '2': case '3': case '4':
>     case '5': case '6': case '7':
>        c = c - '0';
>        if ((*ptr >= '0') && (*ptr <= '7')) { /* added single quotes */
>            c = (c << 3) | (*ptr - '0');
>            ptr++;
>            if ((*ptr >= '0') && (*ptr <= '7')) { /* added single quotes */
>                c = (c << 3) | (*ptr - '0');
>                ptr++;
>            }
>        }
>
> I found this simply by looking at the compiler warnings.
>
> HTH
> Perry
>
> _______________________________________________
> erlang-bugs mailing list
> erlang-bugs@REDACTED
> http://www.erlang.org/mailman/listinfo/erlang-bugs
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://erlang.org/pipermail/erlang-bugs/attachments/20080617/1e70e51f/attachment.htm>


More information about the erlang-bugs mailing list