I think you are right, because the following line <i>requires</i> that *ptr be between '0' and '7'. It appears that this code is packing an octal representation of an ASCII digit into 3 bits.<br><br> c = (c << 3) | (*ptr - '0');<br>
<br><div class="gmail_quote">On Mon, Jun 16, 2008 at 4:12 PM, Perry Smith <<a href="mailto:pedzsan@gmail.com">pedzsan@gmail.com</a>> wrote:<br><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
This looks like a bug to me:<br>
<br>
static char* fmtq(char* ptr, int* buf)<br>
{<br>
int c;<br>
<br>
switch((c=*ptr++)) {<br>
<snip><br>
case '0': case '1': case '2': case '3': case '4':<br>
case '5': case '6': case '7':<br>
c = c - '0';<br>
if ((*ptr >= 0) && (*ptr <= 7)) { <<<<<<br>
c = (c << 3) | (*ptr - '0');<br>
ptr++;<br>
if ((*ptr >= 0) && (*ptr <= 7)) { <<<<<<br>
c = (c << 3) | (*ptr - '0');<br>
ptr++;<br>
}<br>
}<br>
break;<br>
}<br>
*buf = c;<br>
return ptr;<br>
}<br>
<br>
Shouldn't it be:<br>
<br>
case '0': case '1': case '2': case '3': case '4':<br>
case '5': case '6': case '7':<br>
c = c - '0';<br>
if ((*ptr >= '0') && (*ptr <= '7')) { /* added single quotes */<br>
c = (c << 3) | (*ptr - '0');<br>
ptr++;<br>
if ((*ptr >= '0') && (*ptr <= '7')) { /* added single quotes */<br>
c = (c << 3) | (*ptr - '0');<br>
ptr++;<br>
}<br>
}<br>
<br>
I found this simply by looking at the compiler warnings.<br>
<br>
HTH<br>
Perry<br>
<br>
_______________________________________________<br>
erlang-bugs mailing list<br>
<a href="mailto:erlang-bugs@erlang.org">erlang-bugs@erlang.org</a><br>
<a href="http://www.erlang.org/mailman/listinfo/erlang-bugs" target="_blank">http://www.erlang.org/mailman/listinfo/erlang-bugs</a><br>
<br>
</blockquote></div><br>