tomcat-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Ron Egyed" <roneg...@verizon.net>
Subject mod_jk pointer error for i5/OS V5R4
Date Tue, 03 Jul 2007 13:20:49 GMT
FYI,

The following code in the sc_for_req_header function in module jk_ajp_common was getting a
pointer error on version V5R4 of i5/OS (AS400).

while (*p)
      header[i++] = toupper((unsigned char)*p++);

IBM provided two solutions to this problem.
I tried the 2nd solution of wrapping the toupper in parenthesis and the code works correctly
when compiled with LOCALE(*LOCALEUTF).

IBM's explanation. . . 
The reason for the different behavior is that the toupper() routine is implemented as a macro
within the header file and the parameter is evaluated twice for the *LOCALEUTF version of
the routine. 

The standard indicates that the routines within <ctype.h> may be implemented as macros
- http://www.opengroup.org/onlinepubs/007908799/xsh/ctype.h.html 

Any routine which may be implemented as a macro is allowed to evaluate the parameter any number
of times and thus using code like xxx(*p++) where xxx is a runtime routine is not portable.
 The standard does not state this for every routine which may be a macro, but it is true in
all macro cases.  Here is an example within the standard which explicitly states this fact
for the getc() routine - http://www.opengroup.org/onlinepubs/007908799/xsh/getc.html .  Here
is an excerpt from that web page: 

Because it may be implemented as a macro, getc() may treat incorrectly a stream argument with
side effects. In particular, getc(*f++) will not necessarily work as expected. Therefore,
use of this function should be preceded by "#undef getc" in such situations; fgetc() could
also be used. 

This yields the following solutions for such code: 

1) use #undef toupper after <ctype.h> is included. 
2) a second solution is to wrap the toupper call in parenthesis - e.g. (toupper)((unsigned
char)*p++) 

Either of these solutions can be used to 'disable' the macro version and allow both methods
to work correctly. 


Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message