diff --git a/src/frontend/numparam/mystring.c b/src/frontend/numparam/mystring.c index 8918de630..7793473b1 100644 --- a/src/frontend/numparam/mystring.c +++ b/src/frontend/numparam/mystring.c @@ -128,7 +128,7 @@ pscopy(DSTRINGPTR dstr_p, const char *t, const char *stop) } ds_clear(dstr_p); - if (ds_cat_mem(dstr_p, t, stop - t) != DS_E_OK) { + if (ds_cat_mem(dstr_p, t, (size_t) (stop - t)) != DS_E_OK) { controlled_exit(-1); } diff --git a/src/frontend/numparam/spicenum.c b/src/frontend/numparam/spicenum.c index b9cde18fe..4ea618bef 100644 --- a/src/frontend/numparam/spicenum.c +++ b/src/frontend/numparam/spicenum.c @@ -193,7 +193,7 @@ findsubname(dico_t *dico, DSTRINGPTR dstr_p) pscopy(&name, p, t); entry = entrynb(dico, ds_get_buf(&name)); if (entry && (entry->tp == NUPA_SUBCKT)) { - (void) ds_set_length(dstr_p, p_end - s); + (void) ds_set_length(dstr_p, (size_t) (p_end - s)); ds_free(&name); return; } @@ -247,7 +247,7 @@ transform(dico_t *dico, DSTRINGPTR dstr_p, bool incontrol) /* split off any "params" tail */ params = strstr(s, "params:"); if (params) { - ds_set_length(dstr_p, params - s); + ds_set_length(dstr_p, (size_t) (params - s)); } category = 'S'; } else if (prefix(".control", s)) { diff --git a/src/frontend/parser/glob.c b/src/frontend/parser/glob.c index ecdbd2075..49cbe78d7 100644 --- a/src/frontend/parser/glob.c +++ b/src/frontend/parser/glob.c @@ -146,7 +146,7 @@ static wordlist *bracexpand(const wordlist *w_exp) char ch_cur; for ( ; (ch_cur = *p_cur) != '\0'; p_cur++) { if (ch_cur == cp_ocurl) { - offset_ocurl = p_cur - wl_word; + offset_ocurl = (size_t) (p_cur - wl_word); break; } } @@ -246,7 +246,7 @@ static wordlist_l *brac1(size_t offset_ocurl1, const char *p_str) } } - const size_t n_char_append = s - p_start; + const size_t n_char_append = (size_t) (s - p_start); if (n_char_append > 0) { wordlist_l *wl; @@ -330,7 +330,7 @@ static wordlist_l *brac2(const char *string, } else if (ch_cur == cp_ocurl) { /* another brace level started */ if (nb++ == 0) { /* Inc count. If 1st '{', save offset */ - offset_ocurl1 = s - buf_cur; + offset_ocurl1 = (size_t) (s - buf_cur); } } else if ((ch_cur == cp_comma) && (nb == 0)) { @@ -366,7 +366,8 @@ static wordlist_l *brac2(const char *string, * wordlist being built */ { wordlist_l *nwl = brac1( - offset_ocurl1 == SIZE_MAX ? s - buf_cur : offset_ocurl1, + offset_ocurl1 == SIZE_MAX ? + (size_t) (s - buf_cur) : offset_ocurl1, buf_cur); wlist = wll_append(wlist, nwl); } @@ -379,7 +380,7 @@ static wordlist_l *brac2(const char *string, /* When the loop is exited, s is at a brace or comma, which * is also considered to be processed. Hence +2 not +1. */ - *p_n_char_processed = s - buf + 2; + *p_n_char_processed = (size_t) (s - buf + 2); return wlist; } @@ -434,7 +435,7 @@ static void tilde_expand_word(wordlist *wl_node) while ((c = *usr_end) != '\0' && c != DIR_TERM) { ++usr_end; } - const size_t n_char_usr = usr_end - usr_start; + const size_t n_char_usr = (size_t) (usr_end - usr_start); const size_t n_byte_usr = n_char_usr + 1; const char c_orig = c; /* save char to be overwritten by '\0' */ *usr_end = '\0'; @@ -447,7 +448,7 @@ static void tilde_expand_word(wordlist *wl_node) return; /* Strip the ~ and return the rest */ } merge_home_with_rest(wl_node, (size_t) n_char_home, sz_home, - n_char_usr + 1); + n_byte_usr); return; } diff --git a/src/frontend/postcoms.c b/src/frontend/postcoms.c index 0f628424c..4d1a7c1d4 100644 --- a/src/frontend/postcoms.c +++ b/src/frontend/postcoms.c @@ -803,13 +803,9 @@ com_cross(wordlist *wl) vec_remove(newvec); v = dvec_alloc(copy(newvec), - vecs - ? vecs->v_type - : SV_NOTYPE, - comp - ? (VF_COMPLEX | VF_PERMANENT) - : (VF_REAL | VF_PERMANENT), - i, NULL); + (int) (vecs ? vecs->v_type : SV_NOTYPE), + comp ? (VF_COMPLEX | VF_PERMANENT) : (VF_REAL | VF_PERMANENT), + i, NULL); /* Now copy the ind'ths elements into this one. */ for (n = vecs, i = 0; n; n = n->v_link2, i++) diff --git a/src/frontend/postsc.c b/src/frontend/postsc.c index d7e0da70c..b32e4393f 100644 --- a/src/frontend/postsc.c +++ b/src/frontend/postsc.c @@ -108,7 +108,8 @@ static int maxcolor = 2; void PS_LinestyleColor(int linestyleid, int colorid); void PS_SelectColor(int colorid); void PS_Stroke(void); -size_t utf8_to_latin9(char *const output, const char *const input, const size_t length); +static size_t utf8_to_latin9(char * const output, const char *const input, + const size_t length); /* Set scale, color and size of the plot */ @@ -120,10 +121,15 @@ int PS_Init(void) if (!cp_getvar("hcopyscale", CP_STRING, psscale, sizeof(psscale))) { scale = 1.0; - } else { - sscanf(psscale, "%lf", &scale); - if ((scale <= 0) || (scale > 10)) - scale = 1.0; + } + else if (sscanf(psscale, "%lf", &scale) != 1) { + (void) fprintf(cp_err, "Error getting scale value\n"); + scale = 1.0; + } + else if ((scale <= 0.0) || (scale > 10.0)) { + (void) fprintf(cp_err, "Scale value %lf is out of range\n", + scale); + scale = 1.0; } dispdev->numlinestyles = NUMELEMS(linestyle); /* plot color */ @@ -395,12 +401,18 @@ int PS_Arc(int x0, int y0, int r, double theta, double delta_theta) } -int PS_Text(char *text, int x, int y, int angle) +int PS_Text(const char *text_in, int x, int y, int angle) { int savedlstyle, savedcolor; - -#ifndef EXT_ASC - utf8_to_latin9(text, text, strlen(text)); + char *text; +#ifdef EXT_ASC + text = text_in; +#else + { + const size_t n_char_text = strlen(text_in); + text = TMALLOC(char, n_char_text); + utf8_to_latin9(text, text_in, n_char_text); + } #endif /* set linestyle to solid or may get funny color text on some plotters */ @@ -410,12 +422,12 @@ int PS_Text(char *text, int x, int y, int angle) PS_SetLinestyle(SOLID); /* set text color to black if background is not white */ if (setbgcolor > 0) - PS_SetColor(0, currentgraph); + PS_SetColor(0); else - PS_SetColor(1, currentgraph); + PS_SetColor(1); /* if color is given by set hcopytxpscolor=settxcolor, give it a try */ if (settxcolor >= 0) - PS_SetColor(settxcolor, currentgraph); + PS_SetColor(settxcolor); /* stroke the path if there's an open one */ PS_Stroke(); /* move to (x, y) */ @@ -431,8 +443,13 @@ int PS_Text(char *text, int x, int y, int angle) /* restore old linestyle */ - PS_SetColor(savedcolor, currentgraph); + PS_SetColor(savedcolor); PS_SetLinestyle(savedlstyle); + +#ifndef EXT_ASC + txfree(text); +#endif + return 0; } @@ -458,9 +475,8 @@ int PS_SetLinestyle(int linestyleid) } -int PS_SetColor(int colorid, GRAPH *graph) +int PS_SetColor(int colorid) { - NG_IGNORE(graph); PS_LinestyleColor(currentgraph->linestyle, colorid); return 0; } @@ -600,7 +616,8 @@ static inline unsigned int to_latin9(const unsigned int code) * Output has to have room for (length+1) chars, including the trailing NUL byte. from http://stackoverflow.com/questions/11156473/is-there-a-way-to-convert-from-utf8-to-iso-8859-1#11173493 */ -size_t utf8_to_latin9(char *const output, const char *const input, const size_t length) +size_t utf8_to_latin9(char * const output, const char *const input, + const size_t length) { unsigned char *out = (unsigned char *)output; const unsigned char *in = (const unsigned char *)input; diff --git a/src/frontend/vectors.c b/src/frontend/vectors.c index b36ab7125..b746ad154 100644 --- a/src/frontend/vectors.c +++ b/src/frontend/vectors.c @@ -461,7 +461,8 @@ struct dvec *vec_fromplot(char *word, struct plot *plot) { DS_CREATE(ds, 100); const char * const node_start = word + 2; bool ds_ok = ds_cat_mem(&ds, node_start, - p_last_close_paren - node_start) == DS_E_OK; + (size_t) (p_last_close_paren - node_start)) == + DS_E_OK; /* If i(node) or I(node), append #branch */ if (tolower(word[0]) == (int) 'i') { /* i(node) or I(node) */ @@ -807,7 +808,8 @@ struct dvec *vec_copy(struct dvec *v) { nv->v_numdims = v->v_numdims; /* Copy defined dimensions */ - (void) memcpy(nv->v_dims, v->v_dims, v->v_numdims * sizeof *v->v_dims); + (void) memcpy(nv->v_dims, v->v_dims, + (size_t) v->v_numdims * sizeof *v->v_dims); nv->v_plot = v->v_plot; nv->v_next = NULL; @@ -1302,10 +1304,10 @@ vec_mkfamily(struct dvec *v) { d->v_dims[0] = size; if (isreal(v)) { - memcpy(d->v_realdata, v->v_realdata + (size_t) size * i, + memcpy(d->v_realdata, v->v_realdata + (size_t) (size * i), (size_t) size * sizeof(double)); } else { - memcpy(d->v_compdata, v->v_compdata + (size_t) size * i, + memcpy(d->v_compdata, v->v_compdata + (size_t) (size * i), (size_t) size * sizeof(ngcomplex_t)); } /* Add one to the counter. */ diff --git a/src/misc/dstring.c b/src/misc/dstring.c index a02de3078..f3bcbd034 100644 --- a/src/misc/dstring.c +++ b/src/misc/dstring.c @@ -277,7 +277,7 @@ int ds_cat_vprintf(DSTRING *p_ds, const char *sz_fmt, va_list p_arg) /* Else check for buffer large enough and set length if it is */ if ((size_t) rc < n_byte_free) { - p_ds->length += rc; + p_ds->length += (size_t) rc; return DS_E_OK; } @@ -285,7 +285,8 @@ int ds_cat_vprintf(DSTRING *p_ds, const char *sz_fmt, va_list p_arg) { /* Double required size to avoid excessive allocations +1 for * null, which is not included in the count returned by snprintf */ - const size_t n_byte_alloc_min = p_ds->length + rc + 1; + const size_t n_byte_alloc_min = + p_ds->length + (size_t) rc + (size_t) 1; if (ds_reserve_internal(p_ds, 2 * n_byte_alloc_min, n_byte_alloc_min) == DS_E_NO_MEMORY) { /* vsnprintf may have written bytes to the buffer. @@ -307,7 +308,7 @@ int ds_cat_vprintf(DSTRING *p_ds, const char *sz_fmt, va_list p_arg) /* Else update length. No need to check buffer size since it was * sized to fit the string. */ - p_ds->length += rc2; + p_ds->length += (size_t) rc2; return DS_E_OK; } } /* end of function ds_cat_vprintf */ diff --git a/src/misc/string.c b/src/misc/string.c index afbcd80c9..cb9d80b36 100644 --- a/src/misc/string.c +++ b/src/misc/string.c @@ -221,9 +221,10 @@ int get_int_n(const char *str, size_t n, int *p_value) if (!isdigit(ch_cur)) { /* Test for exit due to non-numeric char */ break; } - + /* Compute new value and check for overflow. */ - const unsigned int value_new = 10 * value + (ch_cur - '0'); + const unsigned int value_new = + 10 * value + (unsigned int) (ch_cur - '0'); if (value_new < value) { return -2; } @@ -237,7 +238,7 @@ int get_int_n(const char *str, size_t n, int *p_value) /* Test for overflow. * If negative, can be 1 greater (-2**n vs 2**n -1) */ - if (value - f_neg > (unsigned int) INT_MAX) { + if (value - (unsigned int) f_neg > (unsigned int) INT_MAX) { return -2; } @@ -1253,7 +1254,7 @@ static inline const char *next_substr( for ( ; ; ) { /* Update hash for next starting point at p_string + 1 */ if ((h_string = (((h_string - (unsigned char) p_string[0] * - msb_factor) << 8) + p_string[n_char_pattern]) % + msb_factor) << 8) + (size_t) p_string[n_char_pattern]) % KR_MODULUS) > KR_MODULUS) { /* negative value when signed */ h_string += KR_MODULUS; } diff --git a/src/misc/tilde.c b/src/misc/tilde.c index 1cbc52b35..f2e0b0c3c 100644 --- a/src/misc/tilde.c +++ b/src/misc/tilde.c @@ -70,7 +70,7 @@ char *tildexpand(const char *string) string++; } const char * const usr_end = string; - const size_t n_char_usr = usr_end - usr_start; + const size_t n_char_usr = (size_t) (usr_end - usr_start); const size_t n_byte_usr = n_char_usr + 1; if (n_byte_usr > sizeof buf_fixed) { buf = TMALLOC(char, n_byte_usr);