From cac98897c1edfd9477ded7553a2726764c4e2df6 Mon Sep 17 00:00:00 2001 From: John Mark Bell Date: Sat, 20 Jun 2009 11:23:54 +0000 Subject: Reasons I hate TCPIPLibs: 1) You need to include sys/types.h yourself 2) You need to ensure that netinet/in.h is included before arpa/inet.h 3) Neither arpa/inet.h nor netinet/in.h define htonl/ntohl -- it's in machine/endian.h which, fortunately, is included from sys/types.h Add a bunch of explicit casts to uint32_t to the results of calls to ntohl/htonl to appease Norcroft's "implicit narrowing cast" warning. svn path=/trunk/libparserutils/; revision=7891 --- src/charset/codecs/codec_utf8.c | 32 +++++++++++++++++--------------- 1 file changed, 17 insertions(+), 15 deletions(-) (limited to 'src/charset/codecs/codec_utf8.c') diff --git a/src/charset/codecs/codec_utf8.c b/src/charset/codecs/codec_utf8.c index ad46766..ea192a6 100644 --- a/src/charset/codecs/codec_utf8.c +++ b/src/charset/codecs/codec_utf8.c @@ -8,9 +8,10 @@ #include #include -/* These two are for htonl / ntohl */ -#include +/* These three are for htonl / ntohl */ +#include #include +#include #include @@ -76,9 +77,9 @@ static inline parserutils_error charset_utf8_codec_output_decoded_char( */ bool charset_utf8_codec_handles_charset(const char *charset) { - return parserutils_charset_mibenum_from_name(charset, + return parserutils_charset_mibenum_from_name(charset, strlen(charset)) == - parserutils_charset_mibenum_from_name("UTF-8", + parserutils_charset_mibenum_from_name("UTF-8", SLEN("UTF-8")); } @@ -201,7 +202,7 @@ parserutils_error charset_utf8_codec_encode(parserutils_charset_codec *codec, /* Now process the characters for this call */ while (*sourcelen > 0) { - ucs4 = ntohl(*((uint32_t *) (void *) *source)); + ucs4 = (uint32_t) ntohl(*((uint32_t *) (void *) *source)); towrite = &ucs4; towritelen = 1; @@ -260,9 +261,9 @@ parserutils_error charset_utf8_codec_encode(parserutils_charset_codec *codec, * read, if the result is _OK or _NOMEM. Any remaining output for the * character will be buffered by the codec for writing on the next call. * - * In the case of the result being _INVALID, ::source will point _at_ the - * last input character read; nothing will be written or buffered for the - * failed character. It is up to the client to fix the cause of the failure + * In the case of the result being _INVALID, ::source will point _at_ the + * last input character read; nothing will be written or buffered for the + * failed character. It is up to the client to fix the cause of the failure * and retry the decoding process. * * Note that, if failure occurs whilst attempting to write any output @@ -296,7 +297,8 @@ parserutils_error charset_utf8_codec_decode(parserutils_charset_codec *codec, uint32_t *pread = c->read_buf; while (c->read_len > 0 && *destlen >= c->read_len * 4) { - *((uint32_t *) (void *) *dest) = htonl(pread[0]); + *((uint32_t *) (void *) *dest) = + (uint32_t) htonl(pread[0]); *dest += 4; *destlen -= 4; @@ -403,9 +405,9 @@ parserutils_error charset_utf8_codec_reset(parserutils_charset_codec *codec) * read, if the result is _OK or _NOMEM. Any remaining output for the * character will be buffered by the codec for writing on the next call. * - * In the case of the result being _INVALID, ::source will point _at_ the - * last input character read; nothing will be written or buffered for the - * failed character. It is up to the client to fix the cause of the failure + * In the case of the result being _INVALID, ::source will point _at_ the + * last input character read; nothing will be written or buffered for the + * failed character. It is up to the client to fix the cause of the failure * and retry the decoding process. * * ::sourcelen will be reduced appropriately on exit. @@ -461,9 +463,9 @@ parserutils_error charset_utf8_codec_read_char(charset_utf8_codec *c, } else if (error == PARSERUTILS_INVALID) { /* Illegal input sequence */ uint32_t nextchar; - + /* Strict errormode; simply flag invalid character */ - if (c->base.errormode == + if (c->base.errormode == PARSERUTILS_CHARSET_CODEC_ERROR_STRICT) { /* Clear inval buffer */ c->inval_buf[0] = '\0'; @@ -542,7 +544,7 @@ parserutils_error charset_utf8_codec_output_decoded_char(charset_utf8_codec *c, return PARSERUTILS_NOMEM; } - *((uint32_t *) (void *) *dest) = htonl(ucs4); + *((uint32_t *) (void *) *dest) = (uint32_t) htonl(ucs4); *dest += 4; *destlen -= 4; -- cgit v1.2.3