From 3417680e253b1bfc4519347ef06536378026be2a Mon Sep 17 00:00:00 2001 From: Ben Pfaff Date: Tue, 25 Oct 2005 04:28:17 +0000 Subject: [PATCH] Work to get rid of GCC 4.0 warnings, part 2. In many files, change `unsigned char' to `char'. This often requires adding casts to functions. --- src/ChangeLog | 14 +++++++ src/algorithm.c | 58 +++++++++++++------------- src/ascii.c | 16 +++----- src/case.h | 4 +- src/data-in.c | 97 ++++++++++++++++++++------------------------ src/data-in.h | 4 +- src/groff-font.c | 17 ++++---- src/hash.c | 6 +-- src/lexer.c | 2 +- src/missing-values.c | 9 ++-- src/missing-values.h | 9 ++-- src/pfm-read.c | 17 ++++---- src/pfm-write.c | 2 +- src/postscript.c | 8 ++-- src/recode.c | 2 +- src/repeat.c | 2 +- src/set.q | 2 +- src/settings.h | 2 +- src/sfm-read.c | 16 ++++---- src/sfm-write.c | 4 +- src/str.c | 19 ++++++++- src/str.h | 1 + src/val.h | 4 +- src/value-labels.c | 32 ++++++--------- 24 files changed, 180 insertions(+), 167 deletions(-) diff --git a/src/ChangeLog b/src/ChangeLog index 4df90e33..1ba566d1 100644 --- a/src/ChangeLog +++ b/src/ChangeLog @@ -1,3 +1,17 @@ +Mon Oct 24 21:24:15 2005 Ben Pfaff + + Work to get rid of GCC 4.0 warnings, part 2. + + In many files, change `unsigned char' to `char'. This often + requires adding casts to functions. + + * data-in.c: (parse_A) Use buf_copy_rpad(). + + * str.c: (str_copy_buf_trunc) New function. + + * value-labels.c: (value_to_string) Fix mistaken use of strncpy(), + by rewriting. + Mon Oct 24 13:42:32 WST 2005 John Darrington Moved some definitions to make it easier to abstract a dictionary diff --git a/src/algorithm.c b/src/algorithm.c index 74f2be40..47343e37 100644 --- a/src/algorithm.c +++ b/src/algorithm.c @@ -117,7 +117,7 @@ find (const void *array, size_t count, size_t size, const void *target, algo_compare_func *compare, void *aux) { - const unsigned char *element = array; + const char *element = array; while (count-- > 0) { @@ -139,7 +139,7 @@ count_equal (const void *array, size_t count, size_t size, const void *element, algo_compare_func *compare, void *aux) { - const unsigned char *first = array; + const char *first = array; size_t equal_cnt = 0; while (count-- > 0) @@ -161,7 +161,7 @@ size_t count_if (const void *array, size_t count, size_t size, algo_predicate_func *predicate, void *aux) { - const unsigned char *first = array; + const char *first = array; size_t nonzero_cnt = 0; while (count-- > 0) @@ -294,7 +294,7 @@ is_partitioned (const void *array, size_t count, size_t size, size_t nonzero_cnt, algo_predicate_func *predicate, void *aux) { - const unsigned char *first = array; + const char *first = array; size_t idx; assert (nonzero_cnt <= count); @@ -316,9 +316,9 @@ copy_if (const void *array, size_t count, size_t size, void *result, algo_predicate_func *predicate, void *aux) { - const unsigned char *input = array; - const unsigned char *last = input + size * count; - unsigned char *output = result; + const char *input = array; + const char *last = input + size * count; + char *output = result; size_t nonzero_cnt = 0; while (input < last) @@ -421,9 +421,9 @@ remove_equal (void *array, size_t count, size_t size, void *element, algo_compare_func *compare, void *aux) { - unsigned char *first = array; - unsigned char *last = first + count * size; - unsigned char *result; + char *first = array; + char *last = first + count * size; + char *result; for (;;) { @@ -489,14 +489,14 @@ binary_search (const void *array, size_t count, size_t size, if (count != 0) { - const unsigned char *first = array; + const char *first = array; int low = 0; int high = count - 1; while (low <= high) { int middle = (low + high) / 2; - const unsigned char *element = first + middle * size; + const char *element = first + middle * size; int cmp = compare (value, element, aux); if (cmp > 0) @@ -523,8 +523,8 @@ lexicographical_compare_3way (const void *array1, size_t count1, size_t size, algo_compare_func *compare, void *aux) { - const unsigned char *first1 = array1; - const unsigned char *first2 = array2; + const char *first1 = array1; + const char *first2 = array2; size_t min_count = count1 < count2 ? count1 : count2; while (min_count > 0) @@ -764,7 +764,7 @@ int is_sorted (const void *array, size_t count, size_t size, algo_compare_func *compare, void *aux) { - const unsigned char *first = array; + const char *first = array; size_t idx; for (idx = 0; idx + 1 < count; idx++) @@ -788,11 +788,11 @@ size_t set_difference (const void *array1, size_t count1, void *result_, algo_compare_func *compare, void *aux) { - const unsigned char *first1 = array1; - const unsigned char *last1 = first1 + count1 * size; - const unsigned char *first2 = array2; - const unsigned char *last2 = first2 + count2 * size; - unsigned char *result = result_; + const char *first1 = array1; + const char *last1 = first1 + count1 * size; + const char *first2 = array2; + const char *last2 = first2 + count2 * size; + char *result = result_; size_t result_count = 0; while (first1 != last1 && first2 != last2) @@ -835,8 +835,8 @@ void * adjacent_find_equal (const void *array, size_t count, size_t size, algo_compare_func *compare, void *aux) { - const unsigned char *first = array; - const unsigned char *last = first + count * size; + const char *first = array; + const char *last = first + count * size; while (first < last && first + size < last) { @@ -858,15 +858,15 @@ void push_heap (void *array, size_t count, size_t size, algo_compare_func *compare, void *aux) { - unsigned char *first = array; + char *first = array; size_t i; expensive_assert (count < 1 || is_heap (array, count - 1, size, compare, aux)); for (i = count; i > 1; i /= 2) { - unsigned char *parent = first + (i / 2 - 1) * size; - unsigned char *element = first + (i - 1) * size; + char *parent = first + (i / 2 - 1) * size; + char *element = first + (i - 1) * size; if (compare (parent, element, aux) < 0) SWAP (parent, element, size); else @@ -885,7 +885,7 @@ heapify (void *array, size_t count, size_t size, size_t idx, algo_compare_func *compare, void *aux) { - unsigned char *first = array; + char *first = array; for (;;) { @@ -921,7 +921,7 @@ void pop_heap (void *array, size_t count, size_t size, algo_compare_func *compare, void *aux) { - unsigned char *first = array; + char *first = array; expensive_assert (is_heap (array, count, size, compare, aux)); SWAP (first, first + (count - 1) * size, size); @@ -952,7 +952,7 @@ void sort_heap (void *array, size_t count, size_t size, algo_compare_func *compare, void *aux) { - unsigned char *first = array; + char *first = array; size_t idx; expensive_assert (is_heap (array, count, size, compare, aux)); @@ -972,7 +972,7 @@ int is_heap (const void *array, size_t count, size_t size, algo_compare_func *compare, void *aux) { - const unsigned char *first = array; + const char *first = array; size_t child; for (child = 2; child <= count; child++) diff --git a/src/ascii.c b/src/ascii.c index 63aa4c1d..ae3c805b 100644 --- a/src/ascii.c +++ b/src/ascii.c @@ -202,7 +202,7 @@ ascii_open_global (struct outp_class *this UNUSED) } -static unsigned char *s=0; +static char *s; static int ascii_close_global (struct outp_class *this UNUSED) { @@ -1158,8 +1158,8 @@ text_draw (struct outp_driver *this, struct outp_text *t) /* ascii_close_page () and support routines. */ #define LINE_BUF_SIZE 1024 -static unsigned char *line_buf; -static unsigned char *line_p; +static char *line_buf; +static char *line_p; static inline int commit_line_buf (struct outp_driver *this) @@ -1312,7 +1312,7 @@ output_shorts (struct outp_driver *this, /* Writes CH into line_buf N times, or to THIS->output if line_buf overflows. */ static inline void -output_char (struct outp_driver *this, int n, int ch) +output_char (struct outp_driver *this, int n, char ch) { if (LINE_BUF_SIZE - (line_p - line_buf) >= n) { @@ -1474,7 +1474,7 @@ output_lines (struct outp_driver *this, int first, int count) } if (n_passes > 1) { - unsigned char ch; + char ch; return_carriage (this, n_chars); n_chars = 0; @@ -1538,7 +1538,7 @@ ascii_close_page (struct outp_driver *this) struct ascii_driver_ext *x = this->ext; int nl_len, ff_len, total_len; - unsigned char *cp; + char *cp; int i; assert (this->driver_open && this->page_open); @@ -1624,11 +1624,7 @@ ascii_close_page (struct outp_driver *this) output_string (this, s, &s[total_len]); if (line_p != line_buf && !commit_line_buf (this)) - { - free(s); - s=0; return 0; - } this->page_open = 0; return 1; diff --git a/src/case.h b/src/case.h index 541a3e2e..cf99e022 100644 --- a/src/case.h +++ b/src/case.h @@ -73,7 +73,7 @@ CASE_INLINE void case_from_values (struct ccase *, CASE_INLINE const union value *case_data (const struct ccase *, size_t idx); CASE_INLINE double case_num (const struct ccase *, size_t idx); -CASE_INLINE const unsigned char *case_str (const struct ccase *, size_t idx); +CASE_INLINE const char *case_str (const struct ccase *, size_t idx); CASE_INLINE union value *case_data_rw (struct ccase *, size_t idx); @@ -170,7 +170,7 @@ case_num (const struct ccase *c, size_t idx) return c->case_data->values[idx].f; } -static inline const unsigned char * +static inline const char * case_str (const struct ccase *c, size_t idx) { return c->case_data->values[idx].s; diff --git a/src/data-in.c b/src/data-in.c index 879ad10b..0c21a380 100644 --- a/src/data-in.c +++ b/src/data-in.c @@ -91,10 +91,10 @@ dls_error (const struct data_in *i, const char *format, ...) static void trim_whitespace (struct data_in *i) { - while (i->s < i->e && isspace (i->s[0])) + while (i->s < i->e && isspace ((unsigned char) i->s[0])) i->s++; - while (i->s < i->e && isspace (i->e[-1])) + while (i->s < i->e && isspace ((unsigned char) i->e[-1])) i->e--; } @@ -172,7 +172,7 @@ parse_numeric (struct data_in *i) exponent = 0; for (; have_char (i); i->s++) { - if (isdigit (*i->s)) + if (isdigit ((unsigned char) *i->s)) { digit_cnt++; @@ -219,7 +219,7 @@ parse_numeric (struct data_in *i) /* Get the exponent specified after the `e' or `E'. */ long exp; - if (isalpha (*i->s)) + if (isalpha ((unsigned char) *i->s)) i->s++; if (!parse_int (i, &exp)) { @@ -291,18 +291,18 @@ hexit_value (int c) static inline bool parse_N (struct data_in *i) { - const unsigned char *cp; + const char *cp; i->v->f = 0; for (cp = i->s; cp < i->e; cp++) { - if (!isdigit (*cp)) + if (!isdigit ((unsigned char) *cp)) { dls_error (i, _("All characters in field must be digits.")); return false; } - i->v->f = i->v->f * 10.0 + *cp - '0'; + i->v->f = i->v->f * 10.0 + (*cp - '0'); } apply_implied_decimals (i); @@ -313,14 +313,14 @@ static inline bool parse_PIBHEX (struct data_in *i) { double n; - const unsigned char *cp; + const char *cp; trim_whitespace (i); n = 0.0; for (cp = i->s; cp < i->e; cp++) { - if (!isxdigit (*cp)) + if (!isxdigit ((unsigned char) *cp)) { dls_error (i, _("Unrecognized character in field.")); return false; @@ -345,10 +345,10 @@ parse_RBHEX (struct data_in *i) } { - const unsigned char *cp; + const char *cp; for (cp = i->s; cp < i->e; cp++) - if (!isxdigit (*cp)) + if (!isxdigit ((unsigned char) *cp)) { dls_error (i, _("Field must contain only hex digits.")); return false; @@ -416,7 +416,7 @@ parse_Z (struct data_in *i) /* Copy digits into buf[1 ... len - 1] and terminate string. */ { - const unsigned char *sp; + const char *sp; char *dp; for (sp = i->s, dp = buf + 1; sp < i->e - 1; sp++, dp++) @@ -440,8 +440,8 @@ parse_Z (struct data_in *i) { char *tail; - i->v->f = strtod ((char *) buf, (char **) &tail); - if ((unsigned char *) tail != i->e) + i->v->f = strtod (buf, &tail); + if (tail != i->e) { dls_error (i, _("Error in syntax of zoned decimal number.")); return false; @@ -460,18 +460,18 @@ parse_IB (struct data_in *i) #ifndef WORDS_BIGENDIAN char buf[64]; #endif - const char *p; + const unsigned char *p; unsigned char xor; /* We want the data to be in big-endian format. If this is a little-endian machine, reverse the byte order. */ #ifdef WORDS_BIGENDIAN - p = i->s; + p = (const unsigned char *) i->s; #else memcpy (buf, i->s, i->e - i->s); buf_reverse (buf, i->e - i->s); - p = buf; + p = (const unsigned char *) buf; #endif /* If the value is negative, we need to logical-NOT each value @@ -507,10 +507,10 @@ parse_PIB (struct data_in *i) i->v->f = 0.0; #if WORDS_BIGENDIAN for (j = 0; j < i->e - i->s; j++) - i->v->f = i->v->f * 256.0 + i->s[j]; + i->v->f = i->v->f * 256.0 + (unsigned char) i->s[j]; #else for (j = i->e - i->s - 1; j >= 0; j--) - i->v->f = i->v->f * 256.0 + i->s[j]; + i->v->f = i->v->f * 256.0 + (unsigned char) i->s[j]; #endif apply_implied_decimals (i); @@ -521,15 +521,15 @@ parse_PIB (struct data_in *i) static inline bool parse_P (struct data_in *i) { - const unsigned char *cp; + const char *cp; i->v->f = 0.0; for (cp = i->s; cp < i->e - 1; cp++) { - i->v->f = i->v->f * 10 + (*cp >> 4); + i->v->f = i->v->f * 10 + ((*cp >> 4) & 15); i->v->f = i->v->f * 10 + (*cp & 15); } - i->v->f = i->v->f * 10 + (*cp >> 4); + i->v->f = i->v->f * 10 + ((*cp >> 4) & 15); if ((*cp ^ (*cp >> 1)) & 0x10) i->v->f = -i->v->f; @@ -541,12 +541,12 @@ parse_P (struct data_in *i) static inline bool parse_PK (struct data_in *i) { - const unsigned char *cp; + const char *cp; i->v->f = 0.0; for (cp = i->s; cp < i->e; cp++) { - i->v->f = i->v->f * 10 + (*cp >> 4); + i->v->f = i->v->f * 10 + ((*cp >> 4) & 15); i->v->f = i->v->f * 10 + (*cp & 15); } @@ -566,7 +566,7 @@ parse_RB (struct data_in *i) u; memset (u.c, 0, sizeof u.c); - memcpy (u.c, i->s, min ((int) sizeof (u.c), i->e - i->s)); + memcpy (u.c, i->s, min (sizeof u.c, (size_t) (i->e - i->s))); i->v->f = u.d; return true; @@ -575,16 +575,7 @@ parse_RB (struct data_in *i) static inline bool parse_A (struct data_in *i) { - ptrdiff_t len = i->e - i->s; - - if (len >= i->format.w) - memcpy (i->v->s, i->s, i->format.w); - else - { - memcpy (i->v->s, i->s, len); - memset (i->v->s + len, ' ', i->format.w - len); - } - + buf_copy_rpad (i->v->s, i->format.w, i->s, i->e - i->s); return true; } @@ -600,10 +591,10 @@ parse_AHEX (struct data_in *i) } { - const unsigned char *cp; + const char *cp; for (cp = i->s; cp < i->e; cp++) - if (!isxdigit (*cp)) + if (!isxdigit ((unsigned char) *cp)) { dls_error (i, _("Field must contain only hex digits.")); return false; @@ -669,7 +660,7 @@ parse_int (struct data_in *i, long *result) force_have_char (i); } - if (!isdigit (*i->s)) + if (!isdigit ((unsigned char) *i->s)) { dls_error (i, _("Digit expected in field.")); return false; @@ -678,8 +669,8 @@ parse_int (struct data_in *i, long *result) *result = 0; for (;;) { - *result = *result * 10 + *i->s++ - '0'; - if (!have_char (i) || !isdigit (*i->s)) + *result = *result * 10 + (*i->s++ - '0'); + if (!have_char (i) || !isdigit ((unsigned char) *i->s)) break; } @@ -712,7 +703,7 @@ parse_date_delimiter (struct data_in *i) bool delim = false; while (have_char (i) - && (*i->s == '-' || *i->s == '/' || isspace (*i->s) + && (*i->s == '-' || *i->s == '/' || isspace ((unsigned char) *i->s) || *i->s == '.' || *i->s == ',')) { delim = true; @@ -747,7 +738,7 @@ parse_enum (struct data_in *i, const char *what, /* Consume alphabetic characters. */ name = i->s; length = 0; - while (have_char (i) && isalpha (*i->s)) + while (have_char (i) && isalpha ((unsigned char) *i->s)) { length++; i->s++; @@ -811,7 +802,7 @@ parse_month (struct data_in *i, long *month) if (!force_have_char (i)) return false; - if (isdigit (*i->s)) + if (isdigit ((unsigned char) *i->s)) { if (!parse_int (i, month)) return false; @@ -898,7 +889,7 @@ static bool parse_q_delimiter (struct data_in *i) { skip_whitespace (i); - if (!have_char (i) || tolower (*i->s) != 'q') + if (!have_char (i) || tolower ((unsigned char) *i->s) != 'q') { dls_error (i, _("`Q' expected between quarter and year.")); return false; @@ -925,7 +916,8 @@ parse_wk_delimiter (struct data_in *i) { skip_whitespace (i); if (i->s + 1 >= i->e - || tolower (i->s[0]) != 'w' || tolower (i->s[1]) != 'k') + || tolower ((unsigned char) i->s[0]) != 'w' + || tolower ((unsigned char) i->s[1]) != 'k') { dls_error (i, _("`WK' expected between week and year.")); return false; @@ -940,7 +932,8 @@ parse_time_delimiter (struct data_in *i) { bool delim = false; - while (have_char (i) && (*i->s == ':' || *i->s == '.' || isspace (*i->s))) + while (have_char (i) && (*i->s == ':' || *i->s == '.' + || isspace ((unsigned char) *i->s))) { delim = true; i->s++; @@ -986,24 +979,24 @@ parse_opt_second (struct data_in *i, double *second) char *cp; while (have_char (i) - && (*i->s == ':' || *i->s == '.' || isspace (*i->s))) + && (*i->s == ':' || *i->s == '.' || isspace ((unsigned char) *i->s))) { delim = true; i->s++; } - if (!delim || !isdigit (*i->s)) + if (!delim || !isdigit ((unsigned char) *i->s)) { *second = 0.0; return true; } cp = buf; - while (have_char (i) && isdigit (*i->s)) + while (have_char (i) && isdigit ((unsigned char) *i->s)) *cp++ = *i->s++; if (have_char (i) && *i->s == '.') *cp++ = *i->s++; - while (have_char (i) && isdigit (*i->s)) + while (have_char (i) && isdigit ((unsigned char) *i->s)) *cp++ = *i->s++; *cp = '\0'; @@ -1387,12 +1380,12 @@ data_in (struct data_in *i) if (fmt->cat & FCAT_BLANKS_SYSMIS) { - const unsigned char *cp; + const char *cp; cp = i->s; for (;;) { - if (!isspace (*cp)) + if (!isspace ((unsigned char) *cp)) break; if (++cp == i->e) diff --git a/src/data-in.h b/src/data-in.h index 9499f78c..287b2fbe 100644 --- a/src/data-in.h +++ b/src/data-in.h @@ -34,8 +34,8 @@ enum /* Information about parsing one data field. */ struct data_in { - const unsigned char *s; /* Source start. */ - const unsigned char *e; /* Source end. */ + const char *s; /* Source start. */ + const char *e; /* Source end. */ union value *v; /* Destination. */ diff --git a/src/groff-font.c b/src/groff-font.c index af86e784..a46559ca 100644 --- a/src/groff-font.c +++ b/src/groff-font.c @@ -406,7 +406,7 @@ font_msg (int class, const char *format,...) static void scan_badchars (char *line, int len) { - unsigned char *cp = line; + char *cp = line; /* Same bad characters as Groff. */ static unsigned char badchars[32] = @@ -417,12 +417,15 @@ scan_badchars (char *line, int len) 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, }; - for (; len--; cp++) - if (badchars[*cp >> 3] & (1 << (*cp & 7))) - { - font_msg (SE, _("Bad character \\%3o."), *cp); - *cp = ' '; - } + for (; len--; cp++) + { + int c = (unsigned char) *cp; + if (badchars[c >> 3] & (1 << (c & 7))) + { + font_msg (SE, _("Bad character \\%3o."), *cp); + *cp = ' '; + } + } } /* Character name hashing. */ diff --git a/src/hash.c b/src/hash.c index 019ddb1a..dd6bc3d2 100644 --- a/src/hash.c +++ b/src/hash.c @@ -77,7 +77,7 @@ next_power_of_2 (size_t x) unsigned hsh_hash_bytes (const void *buf_, size_t size) { - const unsigned char *buf = buf_; + const unsigned char *buf = (const unsigned char *) buf_; unsigned hash; assert (buf != NULL); @@ -93,7 +93,7 @@ hsh_hash_bytes (const void *buf_, size_t size) unsigned hsh_hash_string (const char *s_) { - const unsigned char *s = s_; + const unsigned char *s = (const unsigned char *) s_; unsigned hash; assert (s != NULL); @@ -109,7 +109,7 @@ hsh_hash_string (const char *s_) unsigned hsh_hash_case_string (const char *s_) { - const unsigned char *s = s_; + const unsigned char *s = (const unsigned char *) s_; unsigned hash; assert (s != NULL); diff --git a/src/lexer.c b/src/lexer.c index 77d40cfb..66324a25 100644 --- a/src/lexer.c +++ b/src/lexer.c @@ -801,7 +801,7 @@ lex_preprocess_line (void) len--; /* Check for and remove terminal dot. */ - if (len > 0 && s[len - 1] == get_endcmd() ) + if (len > 0 && s[len - 1] == get_endcmd ()) { dot = 1; len--; diff --git a/src/missing-values.c b/src/missing-values.c index 09192179..bda35b20 100644 --- a/src/missing-values.c +++ b/src/missing-values.c @@ -89,7 +89,7 @@ mv_add_value (struct missing_values *mv, const union value *v) missing values. (Long string variables never accept missing values.) */ bool -mv_add_str (struct missing_values *mv, const unsigned char s[]) +mv_add_str (struct missing_values *mv, const char s[]) { assert (mv->width > 0); return mv_add_value (mv, (union value *) s); @@ -223,7 +223,7 @@ using_element (unsigned type, int idx) NEW_WIDTH (inclusive) and OLD_WIDTH (exclusive), false otherwise. */ static bool -can_resize_string (const unsigned char *s, int old_width, int new_width) +can_resize_string (const char *s, int old_width, int new_width) { int i; @@ -302,8 +302,7 @@ mv_is_num_missing (const struct missing_values *mv, double d) MV must be a set of string missing values. S[] must contain exactly as many characters as MV's width. */ bool -mv_is_str_missing (const struct missing_values *mv, - const unsigned char s[]) +mv_is_str_missing (const struct missing_values *mv, const char s[]) { return mv_is_str_user_missing (mv, s); } @@ -348,7 +347,7 @@ mv_is_num_user_missing (const struct missing_values *mv, double d) S[] must contain exactly as many characters as MV's width. */ bool mv_is_str_user_missing (const struct missing_values *mv, - const unsigned char s[]) + const char s[]) { const union value *v = mv->values; assert (mv->width > 0); diff --git a/src/missing-values.h b/src/missing-values.h index 710fc05e..6eff4285 100644 --- a/src/missing-values.h +++ b/src/missing-values.h @@ -50,7 +50,7 @@ bool mv_is_empty (const struct missing_values *); int mv_get_width (const struct missing_values *); bool mv_add_value (struct missing_values *, const union value *); -bool mv_add_str (struct missing_values *, const unsigned char[]); +bool mv_add_str (struct missing_values *, const char[]); bool mv_add_num (struct missing_values *, double); bool mv_add_num_range (struct missing_values *, double low, double high); @@ -68,17 +68,16 @@ typedef bool is_missing_func (const struct missing_values *, /* Is a value system or user missing? */ bool mv_is_value_missing (const struct missing_values *, const union value *); bool mv_is_num_missing (const struct missing_values *, double); -bool mv_is_str_missing (const struct missing_values *, const unsigned char[]); +bool mv_is_str_missing (const struct missing_values *, const char[]); /* Is a value user missing? */ bool mv_is_value_user_missing (const struct missing_values *, const union value *); bool mv_is_num_user_missing (const struct missing_values *, double); -bool mv_is_str_user_missing (const struct missing_values *, - const unsigned char[]); +bool mv_is_str_user_missing (const struct missing_values *, const char[]); /* Is a value system missing? */ bool mv_is_value_system_missing (const struct missing_values *, - const union value *); + const union value *); #endif /* missing-values.h */ diff --git a/src/pfm-read.c b/src/pfm-read.c index 1999628c..24f92833 100644 --- a/src/pfm-read.c +++ b/src/pfm-read.c @@ -59,8 +59,7 @@ struct pfm_reader struct file_handle *fh; /* File handle. */ FILE *file; /* File stream. */ char cc; /* Current character. */ - unsigned char *trans; /* 256-byte character set translation table. */ - + char *trans; /* 256-byte character set translation table. */ int var_cnt; /* Number of variables. */ int weight_index; /* 0-based index of weight variable, or -1. */ int *widths; /* Variable widths, 0 for numeric. */ @@ -342,7 +341,7 @@ read_string (struct pfm_reader *r, char *buf) /* Reads a string and returns a copy of it allocated from R's pool. */ -static unsigned char * +static char * read_pool_string (struct pfm_reader *r) { char string[256]; @@ -356,7 +355,7 @@ read_header (struct pfm_reader *r) { /* portable_to_local[PORTABLE] translates the given portable character into the local character set. */ - static const unsigned char portable_to_local[256] = + static const char portable_to_local[256] = { " " "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz ." @@ -364,7 +363,7 @@ read_header (struct pfm_reader *r) " " }; - unsigned char *trans; + char *trans; int i; /* Read and ignore vanity splash strings. */ @@ -411,6 +410,7 @@ read_header (struct pfm_reader *r) static void read_version_data (struct pfm_reader *r, struct pfm_read_info *info) { + static char empty_string[] = ""; char *date, *time, *product, *author, *subproduct; int i; @@ -419,10 +419,9 @@ read_version_data (struct pfm_reader *r, struct pfm_read_info *info) error (r, "Unrecognized version code `%c'.", r->cc); date = read_pool_string (r); time = read_pool_string (r); - product = match (r, '1') ? read_pool_string (r) : (unsigned char *) ""; - author = match (r, '2') ? read_pool_string (r) : (unsigned char *) ""; - subproduct - = match (r, '3') ? read_pool_string (r) : (unsigned char *) ""; + product = match (r, '1') ? read_pool_string (r) : empty_string; + author = match (r, '2') ? read_pool_string (r) : empty_string; + subproduct = match (r, '3') ? read_pool_string (r) : empty_string; /* Validate file. */ if (strlen (date) != 8) diff --git a/src/pfm-write.c b/src/pfm-write.c index cd088b7b..be9812c5 100644 --- a/src/pfm-write.c +++ b/src/pfm-write.c @@ -246,7 +246,7 @@ write_header (struct pfm_writer *w) { /* PORTME: Translation table from SPSS character code to this computer's native character code (which is probably ASCII). */ - static const unsigned char spss2ascii[256] = + static const char spss2ascii[256] = { "0000000000000000000000000000000000000000000000000000000000000000" "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz ." diff --git a/src/postscript.c b/src/postscript.c index 11473f64..fd738aba 100644 --- a/src/postscript.c +++ b/src/postscript.c @@ -1488,7 +1488,7 @@ quote_ps_name (char *dest, const char *string) const char *sp; for (sp = string; *sp; sp++) - switch (*(unsigned char *) sp) + switch (*sp) { case 'a': case 'f': @@ -1563,7 +1563,7 @@ quote_ps_name (char *dest, const char *string) *dp++ = '<'; for (sp = string; *sp && dp < &dest[256]; sp++) { - sprintf (dp, "%02x", *(unsigned char *) sp); + sprintf (dp, "%02x", (unsigned char) *sp); dp += 2; } return stpcpy (dp, ">cvn"); @@ -1588,7 +1588,7 @@ quote_ps_string (char *dest, const char *string) dp = stpcpy (dp, "\\("); else if (*sp == ')') dp = stpcpy (dp, "\\)"); - else if (*sp < 32 || *((unsigned char *) sp) > 127) + else if (*sp < 32 || (unsigned char) *sp > 127) dp = spprintf (dp, "\\%3o", *sp); else *dp++ = *sp; @@ -2466,7 +2466,7 @@ write_text (struct outp_driver *this, if (TEST_BIT (literal_chars[ext->data], cp->ch)) *lp++ = cp->ch; else - switch (cp->ch) + switch ((char) cp->ch) { case '(': lp = stpcpy (lp, "\\("); diff --git a/src/recode.c b/src/recode.c index a4349826..b630d029 100644 --- a/src/recode.c +++ b/src/recode.c @@ -237,7 +237,7 @@ cmd_recode (void) else { for (i = mark; i < rcd->nmap; i++) - rcd->map[i].t.c = (output.c?xstrdup (output.c):NULL); + rcd->map[i].t.c = output.c ? xstrdup (output.c) : NULL; free (output.c); } } diff --git a/src/repeat.c b/src/repeat.c index a5d2dfb8..593263f8 100644 --- a/src/repeat.c +++ b/src/repeat.c @@ -579,7 +579,7 @@ perform_DO_REPEAT_substitutions (void) } } if (dot) - ds_putc (&output, get_endcmd() ); + ds_putc (&output, get_endcmd ()); ds_destroy (&getl_buf); getl_buf = output; diff --git a/src/set.q b/src/set.q index 300111c9..6bbfd5dc 100644 --- a/src/set.q +++ b/src/set.q @@ -1330,7 +1330,7 @@ get_include(void) return (cmd.inc != STC_OFF ); } -unsigned char +char get_endcmd(void) { return cmd.s_endcmd[0]; diff --git a/src/settings.h b/src/settings.h index 2c426f94..8cff528e 100644 --- a/src/settings.h +++ b/src/settings.h @@ -207,7 +207,7 @@ int get_mxloops(void); int get_nullline(void); /* The character used to terminate commands. */ -unsigned char get_endcmd(void); +char get_endcmd(void); /* Approximate maximum amount of memory to use for cases, in bytes. */ diff --git a/src/sfm-read.c b/src/sfm-read.c index bd8800bb..226c8b31 100644 --- a/src/sfm-read.c +++ b/src/sfm-read.c @@ -89,9 +89,9 @@ struct sfm_var /* Swap bytes *A and *B. */ static inline void -bswap (unsigned char *a, unsigned char *b) +bswap (char *a, char *b) { - unsigned char t = *a; + char t = *a; *a = *b; *b = t; } @@ -100,7 +100,7 @@ bswap (unsigned char *a, unsigned char *b) static inline void bswap_int32 (int32 *x_) { - unsigned char *x = (unsigned char *) x_; + char *x = (char *) x_; bswap (x + 0, x + 3); bswap (x + 1, x + 2); } @@ -109,7 +109,7 @@ bswap_int32 (int32 *x_) static inline void bswap_flt64 (flt64 *x_) { - unsigned char *x = (unsigned char *) x_; + char *x = (char *) x_; bswap (x + 0, x + 7); bswap (x + 1, x + 6); bswap (x + 2, x + 5); @@ -945,7 +945,7 @@ read_variables (struct sfm_reader *r, if (vv->type == NUMERIC) mv_add_num (&vv->miss, mv[j]); else - mv_add_str (&vv->miss, (unsigned char *) &mv[j]); + mv_add_str (&vv->miss, (char *) &mv[j]); } else { @@ -1036,7 +1036,7 @@ read_value_labels (struct sfm_reader *r, { struct label { - unsigned char raw_value[8]; /* Value as uninterpreted bytes. */ + char raw_value[8]; /* Value as uninterpreted bytes. */ union value value; /* Value. */ char *label; /* Null-terminated label string. */ }; @@ -1166,8 +1166,8 @@ read_value_labels (struct sfm_reader *r, if (var[0]->type == ALPHA) { - const int copy_len = min (sizeof (label->raw_value), - sizeof (label->label)); + const int copy_len = min (sizeof label->raw_value, + sizeof label->label); memcpy (label->value.s, label->raw_value, copy_len); } else { flt64 f; diff --git a/src/sfm-write.c b/src/sfm-write.c index 4f0f9ec1..bdde3cf6 100644 --- a/src/sfm-write.c +++ b/src/sfm-write.c @@ -527,8 +527,8 @@ write_value_labels (struct sfm_writer *w, struct variable *v, int idx) *loc++ = vl->value.f; *(unsigned char *) loc = len; - memcpy (&((unsigned char *) loc)[1], vl->label, len); - memset (&((unsigned char *) loc)[1 + len], ' ', + memcpy (&((char *) loc)[1], vl->label, len); + memset (&((char *) loc)[1 + len], ' ', REM_RND_UP (len + 1, sizeof (flt64))); loc += DIV_RND_UP (len + 1, sizeof (flt64)); } diff --git a/src/str.c b/src/str.c index fe9ad814..b70ce97c 100644 --- a/src/str.c +++ b/src/str.c @@ -79,8 +79,8 @@ nvsprintf (char *buf, const char *format, va_list args) void buf_reverse (char *p, size_t nbytes) { - unsigned char *h = p, *t = &h[nbytes - 1]; - unsigned char temp; + char *h = p, *t = &h[nbytes - 1]; + char temp; nbytes /= 2; while (nbytes--) @@ -249,6 +249,21 @@ str_copy_trunc (char *dst, size_t dst_size, const char *src) } } +/* Copies buffer SRC, of SRC_LEN bytes, + to DST, which is in a buffer DST_SIZE bytes long. + Truncates DST to DST_SIZE - 1 characters, if necessary. */ +void +str_copy_buf_trunc (char *dst, size_t dst_size, + const char *src, size_t src_size) +{ + size_t dst_len; + assert (dst_size > 0); + + dst_len = src_size < dst_size ? src_size : dst_size - 1; + memcpy (dst, src, dst_len); + dst[dst_len] = '\0'; +} + /* Converts each character in S to uppercase. */ void str_uppercase (char *s) diff --git a/src/str.h b/src/str.h index 8c9ebc18..db961959 100644 --- a/src/str.h +++ b/src/str.h @@ -106,6 +106,7 @@ void buf_copy_str_rpad (char *, size_t, const char *); int str_compare_rpad (const char *, const char *); void str_copy_rpad (char *, size_t, const char *); void str_copy_trunc (char *, size_t, const char *); +void str_copy_buf_trunc (char *, size_t, const char *, size_t); void str_uppercase (char *); /* Fixed-length strings. */ diff --git a/src/val.h b/src/val.h index 57aaa2af..07b4d794 100644 --- a/src/val.h +++ b/src/val.h @@ -53,7 +53,7 @@ union value double f; /* A short-string value. */ - unsigned char s[MAX_SHORT_STRING]; + char s[MAX_SHORT_STRING]; /* Used by evaluate_expression() to return a string result. As currently implemented, it's a pointer to a dynamic @@ -61,7 +61,7 @@ union value Also used by the AGGREGATE procedure in handling string values. */ - unsigned char *c; + char *c; }; /* Maximum number of `union value's in a single number or string diff --git a/src/value-labels.c b/src/value-labels.c index 7cd8ff0d..8dfbb10e 100644 --- a/src/value-labels.c +++ b/src/value-labels.c @@ -496,29 +496,23 @@ free_atom (void *atom_, void *aux UNUSED) else format it and return the formatted string */ const char * -value_to_string(const union value *val, const struct variable *var) +value_to_string (const union value *val, const struct variable *var) { - static char buf[100]; char *s; - const struct val_labs *val_labs ; - if ( !val || ! var ) - return 0; - - val_labs = var->val_labs; - - - s = val_labs_find (val_labs, *val); + assert (val != NULL); + assert (var != NULL); - if ( s ) - return s; - - if ( 0 == var->width ) - snprintf(buf,100,"%g",val->f); - else + s = val_labs_find (var->val_labs, *val); + if (s == NULL) { - strncpy(buf,val->s,MAX_SHORT_STRING); - strcat(buf,"\0"); + static char buf[256]; + if (var->width != 0) + str_copy_buf_trunc (buf, sizeof buf, val->s, var->width); + else + snprintf(buf, 100, "%g", val->f); + s = buf; } - return buf; + + return s; } -- 2.30.2