10313 iconv_modules: NULL pointer errors
Reviewed by: Robert Mustacchi <rm@joyent.com>
Reviewed by: Gergő Mihály Doma <domag02@gmail.com>
Approved by: Dan McDonald <danmcd@joyent.com>
diff --git a/usr/src/lib/iconv_modules/common/utf8%ibm.c b/usr/src/lib/iconv_modules/common/utf8%ibm.c
index c85e693..98bde56 100644
--- a/usr/src/lib/iconv_modules/common/utf8%ibm.c
+++ b/usr/src/lib/iconv_modules/common/utf8%ibm.c
@@ -29,7 +29,7 @@
 #include <errno.h>
 #include <sys/types.h>
 
-#include "tab_lookup.h"   	/* table lookup data types */
+#include "tab_lookup.h"	/* table lookup data types */
 
 #define MSB     0x80    /* most significant bit */
 #define ONEBYTE 0xff    /* right most byte */
@@ -261,13 +261,8 @@
  * Return: > 0 - converted with enough space in output buffer
  *         = 0 - no space in outbuf
  */
-int utf8_to_ibm(unidx, ibm_code, buf, buflen, st)
-int             unidx;
-unsigned long   ibm_code;
-char            *buf;
-size_t          buflen;
-_icv_state 	*st;
-
+int utf8_to_ibm(int unidx, unsigned long ibm_code, char *buf, size_t buflen,
+    _icv_state *st)
 {
         unsigned long   val;            /* IBM value */
         char            c1, c2, ibm_str[3];
@@ -316,7 +311,7 @@
 
         *buf = ibm_str[0] = c1;
         *(buf+1) = ibm_str[1] = c2;
-        ibm_str[2] = NULL;
+        ibm_str[2] = '\0';
 
 #ifdef DEBUG
     fprintf(stderr, "\t->%x %x<-\n", *buf, *(buf+1));
diff --git a/usr/src/lib/iconv_modules/zh/common/UTF-8%zh_HK.hkscs.c b/usr/src/lib/iconv_modules/zh/common/UTF-8%zh_HK.hkscs.c
index 6e24d65..b397a28 100644
--- a/usr/src/lib/iconv_modules/zh/common/UTF-8%zh_HK.hkscs.c
+++ b/usr/src/lib/iconv_modules/zh/common/UTF-8%zh_HK.hkscs.c
@@ -439,7 +439,7 @@
 
 	*buf = hkscs_str[0] = c1;
 	*(buf+1) = hkscs_str[1] = c2;
-	hkscs_str[2] = NULL;
+	hkscs_str[2] = '\0';
 	}
 
 #ifdef DEBUG
diff --git a/usr/src/lib/iconv_modules/zh/common/UTF-8%zh_TW-big5.c b/usr/src/lib/iconv_modules/zh/common/UTF-8%zh_TW-big5.c
index e7cce94..ae63dac 100644
--- a/usr/src/lib/iconv_modules/zh/common/UTF-8%zh_TW-big5.c
+++ b/usr/src/lib/iconv_modules/zh/common/UTF-8%zh_TW-big5.c
@@ -458,7 +458,7 @@
 
 	*buf = big5_str[0] = c1;
 	*(buf+1) = big5_str[1] = c2;
-	big5_str[2] = NULL;
+	big5_str[2] = '\0';
 	}
 
 #ifdef DEBUG
diff --git a/usr/src/lib/iconv_modules/zh/common/UTF-8%zh_TW-big5p.c b/usr/src/lib/iconv_modules/zh/common/UTF-8%zh_TW-big5p.c
index e10183c..254616c 100644
--- a/usr/src/lib/iconv_modules/zh/common/UTF-8%zh_TW-big5p.c
+++ b/usr/src/lib/iconv_modules/zh/common/UTF-8%zh_TW-big5p.c
@@ -361,7 +361,7 @@
 
 	*buf = big5p_str[0] = c1;
 	*(buf+1) = big5p_str[1] = c2;
-	big5p_str[2] = NULL;
+	big5p_str[2] = '\0';
 	}
 
 #ifdef DEBUG
diff --git a/usr/src/lib/iconv_modules/zh/common/UTF-8%zh_TW-euc.c b/usr/src/lib/iconv_modules/zh/common/UTF-8%zh_TW-euc.c
index 085e5a9..bac7933 100644
--- a/usr/src/lib/iconv_modules/zh/common/UTF-8%zh_TW-euc.c
+++ b/usr/src/lib/iconv_modules/zh/common/UTF-8%zh_TW-euc.c
@@ -397,7 +397,7 @@
 static int get_plane_no_by_utf(uint_t unicode,
 			int *unidx, unsigned long *cnscode)
 {
-	int 		ret;
+	int		ret;
 
         /* test whether it belongs to private Unicode plane 15 */
         if (unicode >= Low_UDA_In_Unicode && unicode <= High_UDA_In_Unicode)
@@ -486,7 +486,7 @@
 		if ( buflen < 2) goto err;
 		*buf = cns_str[0] = c1;
 		*(buf+1) = cns_str[1] = c2;
-		cns_str[2] = cns_str[3] = cns_str[4] = NULL;
+		cns_str[2] = cns_str[3] = cns_str[4] = '\0';
 		ret_size = 2;
 		break;
 	case 2:
@@ -509,7 +509,7 @@
 		*(buf+1) = cns_str[1] = PMASK + plane_no;
 		*(buf+2) = cns_str[2] = c1;
 		*(buf+3) = cns_str[3] = c2;
-		cns_str[4] = NULL;
+		cns_str[4] = '\0';
 		ret_size = 4;
 		break;
 	}
diff --git a/usr/src/lib/iconv_modules/zh/common/zh_TW-big5%zh_TW-euc.c b/usr/src/lib/iconv_modules/zh/common/zh_TW-big5%zh_TW-euc.c
index 6b2394c..6022084 100644
--- a/usr/src/lib/iconv_modules/zh/common/zh_TW-big5%zh_TW-euc.c
+++ b/usr/src/lib/iconv_modules/zh/common/zh_TW-big5%zh_TW-euc.c
@@ -234,7 +234,7 @@
 static int get_plane_no_by_big5(const char c1, const char c2,
 			int *unidx, unsigned long *cnscode)
 {
-	int 		ret;
+	int		ret;
 	unsigned long	big5code;
 
 	big5code = (unsigned long) ((c1 & ONEBYTE) << 8) + (c2 & ONEBYTE);
@@ -300,7 +300,7 @@
 		if ( buflen < 2 ) goto err;
 		*buf = cns_str[0] = c1;
 		*(buf+1) = cns_str[1] = c2;
-		cns_str[2] = cns_str[3] = cns_str[4] = NULL;
+		cns_str[2] = cns_str[3] = cns_str[4] = '\0';
 		ret_size = 2;
 		break;
 	case 2:
@@ -323,7 +323,7 @@
 		*(unsigned char*)(buf+1) = cns_str[1] = PMASK + plane_no;
 		*(unsigned char*) (buf+2) = cns_str[2] = c1;
 		*(unsigned char*) (buf+3) = cns_str[3] = c2;
-		cns_str[4] = NULL;
+		cns_str[4] = '\0';
 		ret_size = 4;
 		break;
 	}
diff --git a/usr/src/lib/iconv_modules/zh/common/zh_TW-euc%UTF-8.c b/usr/src/lib/iconv_modules/zh/common/zh_TW-euc%UTF-8.c
index 57955c7..4c9f0ac 100644
--- a/usr/src/lib/iconv_modules/zh/common/zh_TW-euc%UTF-8.c
+++ b/usr/src/lib/iconv_modules/zh/common/zh_TW-euc%UTF-8.c
@@ -194,7 +194,7 @@
 					int uconv_num_internal = 0;
 
 					st->keepc[1] = (**inbuf);
-					st->keepc[2] = st->keepc[3] = NULL;
+					st->keepc[2] = st->keepc[3] = '\0';
 					n = cns_to_utf8(1, st, *outbuf,
 							*outbytesleft, &uconv_num_internal);
 					if (n > 0) {
diff --git a/usr/src/lib/iconv_modules/zh/common/zh_TW-euc%zh_TW-big5.c b/usr/src/lib/iconv_modules/zh/common/zh_TW-euc%zh_TW-big5.c
index bef3fda..c87c961 100644
--- a/usr/src/lib/iconv_modules/zh/common/zh_TW-euc%zh_TW-big5.c
+++ b/usr/src/lib/iconv_modules/zh/common/zh_TW-euc%zh_TW-big5.c
@@ -153,7 +153,7 @@
 			} else {	/* 2-byte Chinese character - plane #1 */
 				if (**inbuf & MSB) {	/* plane #1 */
 					st->keepc[1] = (**inbuf);
-					st->keepc[2] = st->keepc[3] = NULL;
+					st->keepc[2] = st->keepc[3] = '\0';
 					n = cns_to_big5(1, st->keepc, *outbuf,
 							*outbytesleft);
 					if (n > 0) {
diff --git a/usr/src/lib/iconv_modules/zh/common/zh_TW-euc%zh_TW-iso2022-7.c b/usr/src/lib/iconv_modules/zh/common/zh_TW-euc%zh_TW-iso2022-7.c
index 3b66d25..889d6cb 100644
--- a/usr/src/lib/iconv_modules/zh/common/zh_TW-euc%zh_TW-iso2022-7.c
+++ b/usr/src/lib/iconv_modules/zh/common/zh_TW-euc%zh_TW-iso2022-7.c
@@ -207,7 +207,7 @@
 				if (**inbuf & MSB) {	/* plane #1 */
 					st->cstate = C4;
 					st->keepc[1] = (**inbuf);
-					st->keepc[2] = st->keepc[3] = NULL;
+					st->keepc[2] = st->keepc[3] = '\0';
 					plane_no = 1;
 					continue;       /* should not advance *inbuf */
 				} else {	/* input char doesn't belong
@@ -403,10 +403,10 @@
 _cv_enconv(struct _cv_state *st, char **cvinbuf, size_t *cvinbytesleft,
 				char **cvoutbuf, size_t *cvoutbytesleft)
 {
-	register char 	*inbuf;
-	register char	*outbuf;
-	register size_t insize;
-	register size_t outsize;
+	char	*inbuf;
+	char	*outbuf;
+	size_t insize;
+	size_t outsize;
 
 	unsigned char	uc;
 	int		i;
diff --git a/usr/src/lib/iconv_modules/zh/common/zh_TW-iso2022-7%UTF-8.c b/usr/src/lib/iconv_modules/zh/common/zh_TW-iso2022-7%UTF-8.c
index 08f31be..12b3713 100644
--- a/usr/src/lib/iconv_modules/zh/common/zh_TW-iso2022-7%UTF-8.c
+++ b/usr/src/lib/iconv_modules/zh/common/zh_TW-iso2022-7%UTF-8.c
@@ -242,7 +242,7 @@
 			break;
 		case C6:		/* plane #1: 2nd Chinese character */
 			st->keepc[1] = (char) (**inbuf | MSB);
-			st->keepc[2] = st->keepc[3] = NULL;
+			st->keepc[2] = st->keepc[3] = '\0';
 			n = iso_to_utf8(1, st->keepc, *outbuf,
 						*outbytesleft);
 			if (n > 0) {
diff --git a/usr/src/lib/iconv_modules/zh/common/zh_TW-iso2022-7%zh_TW-big5.c b/usr/src/lib/iconv_modules/zh/common/zh_TW-iso2022-7%zh_TW-big5.c
index 9113b82..a2db1a3 100644
--- a/usr/src/lib/iconv_modules/zh/common/zh_TW-iso2022-7%zh_TW-big5.c
+++ b/usr/src/lib/iconv_modules/zh/common/zh_TW-iso2022-7%zh_TW-big5.c
@@ -242,7 +242,7 @@
 			break;
 		case C6:		/* plane #1: 2nd Chinese character */
 			st->keepc[1] = (char) (**inbuf | MSB);
-			st->keepc[2] = st->keepc[3] = NULL;
+			st->keepc[2] = st->keepc[3] = '\0';
 			n = iso_to_big5(1, st->keepc, *outbuf, *outbytesleft);
 			if (n > 0) {
 				(*outbuf) += n;
diff --git a/usr/src/lib/iconv_modules/zh/common/zh_TW-iso2022-7%zh_TW-euc.c b/usr/src/lib/iconv_modules/zh/common/zh_TW-iso2022-7%zh_TW-euc.c
index 4fcdb8e..a7a45db 100644
--- a/usr/src/lib/iconv_modules/zh/common/zh_TW-iso2022-7%zh_TW-euc.c
+++ b/usr/src/lib/iconv_modules/zh/common/zh_TW-iso2022-7%zh_TW-euc.c
@@ -104,7 +104,7 @@
 };
 
 extern	TWNiconv * aTWNiconv();
-extern	void 	adeTWNiconv(TWNiconv *);
+extern	void	adeTWNiconv(TWNiconv *);
 extern	size_t	aisotoeuc(TWNiconv *, char **, size_t *, char **, size_t *);
 extern	void	areset(TWNiconv *);
 
@@ -306,7 +306,7 @@
 			break;
 		case C6:		/* plane #1: 2nd Chinese character */
 			st->keepc[1] = (char) (**inbuf | MSB);
-			st->keepc[2] = st->keepc[3] = NULL;
+			st->keepc[2] = st->keepc[3] = '\0';
 			n = iso_to_cns(1, st->keepc, *outbuf, *outbytesleft);
 			if (n > 0) {
 				(*outbuf) += n;
diff --git a/usr/src/lib/iconv_modules/zh/common/zh_TW-iso2022-CN-EXT%zh_TW-big5.c b/usr/src/lib/iconv_modules/zh/common/zh_TW-iso2022-CN-EXT%zh_TW-big5.c
index f0ce186..059e014 100644
--- a/usr/src/lib/iconv_modules/zh/common/zh_TW-iso2022-CN-EXT%zh_TW-big5.c
+++ b/usr/src/lib/iconv_modules/zh/common/zh_TW-iso2022-CN-EXT%zh_TW-big5.c
@@ -60,7 +60,7 @@
 {
 
 	table_t key, *ptr;
-	if ( st->SSfunc == NULL && st->SOcharset == 'A') {	/* GB2312 */
+	if ( st->SSfunc == NONE && st->SOcharset == 'A') {	/* GB2312 */
 	    return gb_to_big5(st, outbuf, outbytesleft);
 	}
 
diff --git a/usr/src/lib/iconv_modules/zh/common/zh_TW-iso2022-CN-EXT%zh_TW-euc.c b/usr/src/lib/iconv_modules/zh/common/zh_TW-iso2022-CN-EXT%zh_TW-euc.c
index b1e8f5b..1b1028c 100644
--- a/usr/src/lib/iconv_modules/zh/common/zh_TW-iso2022-CN-EXT%zh_TW-euc.c
+++ b/usr/src/lib/iconv_modules/zh/common/zh_TW-iso2022-CN-EXT%zh_TW-euc.c
@@ -54,7 +54,7 @@
 chinese_to_euc( _iconv_st *st, unsigned char **outbuf, size_t *outbytesleft, int plane_no )
 {
 
-	if ( st->SSfunc == NULL && st->SOcharset == 'A') {	/* GB2312 */
+	if ( st->SSfunc == NONE && st->SOcharset == 'A') {	/* GB2312 */
 	    return gb_to_euc(st, outbuf, outbytesleft);
 	}
 
diff --git a/usr/src/lib/iconv_modules/zh/common/zh_TW-iso2022-CN-EXT.c b/usr/src/lib/iconv_modules/zh/common/zh_TW-iso2022-CN-EXT.c
index 9718178..0273e05 100644
--- a/usr/src/lib/iconv_modules/zh/common/zh_TW-iso2022-CN-EXT.c
+++ b/usr/src/lib/iconv_modules/zh/common/zh_TW-iso2022-CN-EXT.c
@@ -64,9 +64,9 @@
 	st->ESCstate = OFF;
 	st->firstbyte = True;
 	st->numsav = 0;
-	st->SOcharset = NULL;		/* no default charset */
-	st->SS2charset = NULL;		/* no default charset */
-	st->SS3charset = NULL;		/* no default charset */
+	st->SOcharset = 0;		/* no default charset */
+	st->SS2charset = 0;		/* no default charset */
+	st->SS3charset = 0;		/* no default charset */
 	st->nonidcount = 0;
 	st->_errno = 0;
 
@@ -123,9 +123,9 @@
 	    st->ESCstate = OFF;
 	    st->firstbyte = True;
 	    st->numsav = 0;
-	    st->SOcharset = NULL;
-	    st->SS2charset = NULL;
-	    st->SS3charset = NULL;
+	    st->SOcharset = 0;
+	    st->SS2charset = 0;
+	    st->SS3charset = 0;
 	    st->nonidcount = 0;
 	    st->_errno = 0;
 	    return ((size_t) 0);
@@ -182,7 +182,7 @@
 	    } else if ( st->ESCstate != OFF ) { /* Continue processing the
 						  escape sequence */
 		ret = process_esc_seq( **inbuf, st );
-		if ( ret == DONE ) { 	/* ESC seq interpreted correctly.
+		if ( ret == DONE ) {	/* ESC seq interpreted correctly.
 					     Switch off the escape machine */
 		    st->ESCstate = OFF;
 		} else if ( ret == INVALID ){
@@ -207,13 +207,13 @@
 			st->_errno = errno = EILSEQ;
 			st->nonidcount += 1; /* For this character */
 		    }
-		    st->numsav = 0; 	 /* Discard the saved characters of
+		    st->numsav = 0;	 /* Discard the saved characters of
 					    invalid sequence */
 		    st->ESCstate = OFF;
 		} /* more char. needed for escape sequence */
 	    } else if (st->Sfunc  == SI) {
 		/* Switch state to SO only if SOdesignation is set. */
-		if ( **inbuf == SO && st->SOcharset != NULL ){
+		if ( **inbuf == SO && st->SOcharset != 0 ){
 		    st->Sfunc = SO;
 		} else { /* Is ASCII */
 		    n = ascii_to_euc(**inbuf, st, outbuf, outbytesleft );
@@ -268,7 +268,7 @@
 	case E0:
 	    switch (c){
 	    case SS2LOW:
-		if ( st->SS2charset == NULL ){
+		if ( st->SS2charset == 0 ){
 		    /* We do not expect SS2 shift function before
 		       SS2 designation is set */
 		    st->savbuf[0] = ESC;
@@ -281,7 +281,7 @@
 		st->nonidcount -= 1;
 		return(DONE);
 	    case SS3LOW:
-		if ( st->SS3charset == NULL ){
+		if ( st->SS3charset == 0 ){
 		    /* We do not expect SS3 shift function before
 		       SS3 designation is set */
 		    st->savbuf[0] = ESC;
@@ -384,7 +384,7 @@
 {
 	int plane_no = -1;
 
-	if ( st->SSfunc == NULL && st->SOcharset == 'G' )
+	if ( st->SSfunc == NONE && st->SOcharset == 'G' )
 	    plane_no = 1;
 	else if ( st->SSfunc == SS2 && st->SS2charset == 'H' )
 	    plane_no = 2;