[erlang-bugs] fmtq bug by inspection

Rickard Green rickard.s.green@REDACTED
Wed Jun 18 15:52:37 CEST 2008


Hi Perry,

Thanks for the bug report. I looked a little closer at it, and it turns 
out that the use of fmtq() should be removed. erts_printf will currently 
produce erroneous results when double backslashes are used in format 
strings. I wasn't able to find any format strings like that being passed 
to erts_printf in the emulator, i.e., the bug is currently completely 
harmless. The bug will be fixed in R12B-4, though.

BR,
Rickard, Erlang/OTP, Ericsson AB.

Perry Smith 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
> 



More information about the erlang-bugs mailing list