[OPEN-ILS-DEV] C nits: utils.c (Part 7)

Scott McKellar mck9 at swbell.net
Mon Apr 16 22:59:39 EDT 2007


The uescape function copies a string, while applying certain
transformations:

1. Certain characters are expressed with escaping backslashes;

2. ASCII control characters, when not escaped as described above, are
expressed in hex;

3. Non-ASCII Unicode characters are expressed in hex.

Some character values are invalid.  If we see one, we return NULL
instead of a pointer to a string.  This presumably doesn't happen
very often, but if it does, we leak memory.  Before returning NULL
we should call buffer_free() to destroy the growing_buffer.

In order to express something in hex, we call buffer_fadd(), passing
it a printf-style format string "\\u%04x".  The corresponding value
is c, an unsigned long.  However the format string uses a conversion
specification for an ordinary unsigned int.  It doesn't make any
visible difference on a system where ints and longs are the same
size, but they aren't always.  The format string should really be 
"\\u%04lx".

Scott McKellar
http://home.swbell.net/mck9/aargh/



More information about the Open-ils-dev mailing list