From 4b2c50f6d20f27868a140d58c6043880c7a7f510 Mon Sep 17 00:00:00 2001 From: Renaud Fivet Date: Mon, 16 Feb 2015 13:41:59 +0800 Subject: [PATCH] Clean up splint warnings: - Inconsistencies between defines.h and estruct.h. - Review scope of termio local variables. - Type mismatch in utf8. --- Makefile | 5 ++++- defines.h | 10 ++++++++++ termio.c | 13 ++++++------- utf8.c | 42 +++++++++++++++++++++++++----------------- 4 files changed, 45 insertions(+), 25 deletions(-) diff --git a/Makefile b/Makefile index 973e7d2..ca9c51b 100644 --- a/Makefile +++ b/Makefile @@ -43,7 +43,7 @@ ifeq ($(uname_S),Darwin) DEFINES=-DAUTOCONF -DPOSIX -DSYSV -D_DARWIN_C_SOURCE -D_BSD_SOURCE -D_SVID_SOURCE -D_XOPEN_SOURCE=600 endif ifeq ($(uname_S),CYGWIN) - DEFINES=-DAUTOCONF -DCYGWIN -DPROGRAM=$(PROGRAM) + DEFINES=-DAUTOCONF -DCYGWIN -DSYSV -DPROGRAM=$(PROGRAM) LIBS=-lcurses endif ifeq ($(uname_S),MINGW32) @@ -86,6 +86,9 @@ lint: ${SRC} lint ${LFLAGS} ${SRC} >lintout cat lintout +splint: + splint $(DEFINES) $(SRC) -booltype boolean -booltrue TRUE -boolfalse FALSE +posixlib + errs: @rm -f makeout make $(PROGRAM) >makeout diff --git a/defines.h b/defines.h index 0962da3..22a28d0 100644 --- a/defines.h +++ b/defines.h @@ -1,3 +1,9 @@ +/* defines.h -- */ + +#ifndef __DEFINES_H__ +#define __DEFINES_H__ + + /* Must define one of VMS | V7 | USG | BSD | MSDOS */ @@ -18,3 +24,7 @@ if smaller font or portrait orientation limit to 400x150 */ #define MAXCOL 400 #define MAXROW 150 + +#endif + +/* end of defines.h */ diff --git a/termio.c b/termio.c index e81a8d2..797232b 100644 --- a/termio.c +++ b/termio.c @@ -20,7 +20,6 @@ #include "utf8.h" -/* rfi */ #include #include @@ -58,12 +57,12 @@ int nxtchar = -1; /* character held from type ahead */ #include #include #include -int kbdflgs; /* saved keyboard fd flags */ -int kbdpoll; /* in O_NDELAY mode */ -int kbdqp; /* there is a char in kbdq */ -char kbdq; /* char we've already read */ -struct termio otermio; /* original terminal characteristics */ -struct termio ntermio; /* charactoristics to use inside */ +static int kbdflgs ; /* saved keyboard fd flags */ +static int kbdpoll ; /* in O_NDELAY mode */ +static int kbdqp ; /* there is a char in kbdq */ +static char kbdq ; /* char we've already read */ +static struct termio otermio ; /* original terminal characteristics */ +static struct termio ntermio ; /* characteristics to use inside */ #if XONXOFF #define XXMASK 0016000 #endif diff --git a/utf8.c b/utf8.c index 6536d13..3b122d7 100644 --- a/utf8.c +++ b/utf8.c @@ -1,3 +1,5 @@ +/* utf8.c -- implements utf8.h, converts between unicode and UTF-8 */ + #include "utf8.h" #include @@ -18,8 +20,8 @@ unsigned utf8_to_unicode(char *line, unsigned index, unsigned len, unicode_t *res) { unicode_t value ; - unsigned char c = line[index]; - unsigned bytes, mask, i; + unsigned c = line[ index] & 0xFFU ; + unsigned bytes, mask, i; *res = c; @@ -36,12 +38,12 @@ unsigned utf8_to_unicode(char *line, unsigned index, unsigned len, unicode_t *re /* Ok, it's 11xxxxxx, do a stupid decode */ mask = 0x20; bytes = 2; - while (c & mask) { + while( (c & mask) != 0) { bytes++; mask >>= 1; } - /* bytes is in range [2..4] */ + /* bytes is in range [2..4] as c was in range [C2..F4] */ len -= index; if (bytes > len) return 1; @@ -51,7 +53,7 @@ unsigned utf8_to_unicode(char *line, unsigned index, unsigned len, unicode_t *re /* Ok, do the bytes */ line += index; for (i = 1; i < bytes; i++) { - c = line[i]; + c = line[i] & 0xFFU ; if ((c & 0xc0) != 0x80) return 1; value = (value << 6) | (c & 0x3f); @@ -85,7 +87,7 @@ static void reverse_string(char *begin, char *end) * overlong utf-8 sequences. */ unsigned unicode_to_utf8( unicode_t c, char *utf8) { - int bytes = 1 ; + unsigned bytes = 1 ; assert( c <= 0x10FFFF) ; @@ -94,18 +96,24 @@ unsigned unicode_to_utf8( unicode_t c, char *utf8) { c &= 0xFF ; #endif - *utf8 = c ; - if (c > 0x7f) { - int prefix = 0x40; - char *p = utf8; + if( c <= 0x7f) + *utf8 = (char) c ; + else { + unsigned prefix = 0x40 ; + char *p = utf8 ; do { - *p++ = 0x80 + (c & 0x3f); - bytes++; - prefix >>= 1; - c >>= 6; + *p++ = (char) (0x80 + (c & 0x3f)) ; + bytes++ ; + prefix >>= 1 ; + c >>= 6 ; } while( c >= prefix) ; - *p = c - 2*prefix; - reverse_string(utf8, p); + + *p = (char) (c - 2 * prefix) ; + reverse_string( utf8, p) ; } - return bytes; + + return bytes ; } + + +/* end of utf8.c */