[Common-dev] CR: common/util/pub/hxstrutl.h

[Common-dev] CR: common/util/pub/hxstrutl.h

Henry Ping ping at real.com
Thu Sep 9 15:38:56 PDT 2004


looks good

-->Henry

At 03:24 PM 9/9/2004 -0700, Jeremy Chaney wrote:
>Modified by: Jeremy Chaney
>Reviewed by:  Henry Ping
>Date: 9/8/2004
>Project: common/util
>
>Synopsis:
>According to C99 7.4/1:
>---------------
>The header <ctype.h> declares several functions useful for
>classifying and mapping characters. In all cases the argument is an
>int, the value of which shall be representable as an unsigned char or
>shall equal the value of the macro EOF. If the argument has any other
>value, the behavior is undefined.
>---------------
>
>The IS_SPACE macro attempts to prevent undefined behavior (which happens 
>to be a crash in VC7) by capping values at 0x7F- any signed char greater 
>than that will be bit extended isspace()  converts it into an unsigned int.
>
>Fix: In practice this works because there are no space characters above 
>0x7F, but a better fix is to simply typecast the value to an unsigned char 
>before passing it to isspace(). This ensures that any and all values 
>representable as unsigned char are handled by the C-Runtime. I also added 
>a big fat comment explaining why the IS_SPACE macro is needed.
>
>Files Modified: hxstrutl.h
>
>
>Branch:  hxclient_ipv4_2004-05-19 and HEAD
>Copyright assignment*:* I am a RealNetworks employee or contractor
>
>Diff:
>===================================================================
>RCS file: /cvsroot/common/util/pub/hxstrutl.h,v
>retrieving revision 1.6
>diff -u -w -r1.6 hxstrutl.h
>--- hxstrutl.h    8 Apr 2003 18:31:07 -0000    1.6
>+++ hxstrutl.h    9 Sep 2004 22:03:04 -0000
>@@ -95,7 +95,19 @@
>#define MAX_NUMBER_OF_COOKIES    300
>#define MAX_COOKIES_PER_SERVER    20
>-#define IS_SPACE(x)    ((((unsigned int) (x)) > 0x7f) ? 0 : isspace(x))
>+/*
>+According to C99 7.4/1:
>+---------------
>+The header <ctype.h> declares several functions useful for
>+classifying and mapping characters. In all cases the argument is an
>+int, the value of which shall be representable as an unsigned char or
>+shall equal the value of the macro EOF. If the argument has any other
>+value, the behavior is undefined.
>+---------------
>+Typecast the value to an (unsigned char) before passing it to isspace() 
>to ensure that
>+if the value is a signed char it doesn't get bit extended on certain (VC) 
>compilers.
>+*/
>+#define IS_SPACE(x)    (isspace((unsigned char) x))
>#ifdef __cplusplus
>void        StrAllocCopy(char*& pDest, char* pSrc);
>
>
>_______________________________________________
>Common-dev mailing list
>Common-dev at lists.helixcommunity.org
>http://lists.helixcommunity.org/mailman/listinfo/common-dev




More information about the Common-dev mailing list
 

Site Map   |   Terms of Use   |   Privacy Policy   |   Contact Us

Copyright © 1995-2007 RealNetworks, Inc. All rights reserved. RealNetworks and Helix are trademarks of RealNetworks.
All other trademarks or registered trademarks are the property of their respective holders.