From e100aaf6b0be0e258bd09c37aca783ca1ae06ff2 Mon Sep 17 00:00:00 2001 From: Ward Fisher Date: Tue, 7 Feb 2017 14:20:59 -0700 Subject: [PATCH] We cannot assume char is signed or unsigned. --- libsrc/ncx.m4 | 4 ++-- nc_test/util.c | 11 ++++++----- 2 files changed, 8 insertions(+), 7 deletions(-) diff --git a/libsrc/ncx.m4 b/libsrc/ncx.m4 index f3664e375..837291954 100644 --- a/libsrc/ncx.m4 +++ b/libsrc/ncx.m4 @@ -2426,7 +2426,7 @@ dnl define(`NCX_GETN_Byte_Body',dnl `dnl (void) memcpy(tp, *xpp, (size_t)nelems); - *xpp = (void *)((char *)(*xpp) + nelems); + *xpp = (void *)((schar *)(*xpp) + nelems); return NC_NOERR; ')dnl dnl dnl dnl @@ -2441,7 +2441,7 @@ define(`NCX_PAD_GETN_Byte_Body',dnl rndup = X_ALIGN - rndup; (void) memcpy(tp, *xpp, (size_t)nelems); - *xpp = (void *)((char *)(*xpp) + nelems + rndup); + *xpp = (void *)((schar *)(*xpp) + nelems + rndup); return NC_NOERR; ')dnl diff --git a/nc_test/util.c b/nc_test/util.c index 9b3b87298..26c19f144 100644 --- a/nc_test/util.c +++ b/nc_test/util.c @@ -979,7 +979,7 @@ void check_vars(int ncid) { size_t index[MAX_RANK]; - char text, name[NC_MAX_NAME]; + signed char text, name[NC_MAX_NAME]; int i, err; /* status */ size_t j; int nok = 0; /* count of valid comparisons */ @@ -987,6 +987,7 @@ check_vars(int ncid) double value, expect; nc_type xtype; size_t length; + signed char tmp_char; for (i = 0; i < numVars; i++) { isChar = var_type[i] == NC_CHAR; @@ -1013,11 +1014,11 @@ check_vars(int ncid) expect = hash( var_type[i], var_rank[i], index ); if (isChar) { err = nc_get_var1_text(ncid, i, index, &text); - IF (err) + IF (err) error("nc_get_var1_text: %s", nc_strerror(err)); - IF (text != (char)expect) { - error("Var %s [%lu] value read %hhd not that expected %g ", - var_name[i], j, text, expect); + IF (text != expect) { + error("Var %s [%lu] value read %hhd not that expected %g ", + var_name[i], j, text, expect); print_n_size_t(var_rank[i], index); } else { nok++;