From bb10b84045c4191fefa5a0bfcaddbb41ce70e5bf Mon Sep 17 00:00:00 2001 From: Jim Monte Date: Mon, 9 Dec 2019 00:27:03 -0500 Subject: [PATCH] Fixed buffer resizing, made string utilities more modular, and added several new utilities, some which do not require a null termination, potentially avoiding the need to copy a string. Also some substring utilities using the Rabin-Karp algorithm were added. --- src/include/ngspice/stringutil.h | 4 +--- src/misc/string.c | 2 +- 2 files changed, 2 insertions(+), 4 deletions(-) diff --git a/src/include/ngspice/stringutil.h b/src/include/ngspice/stringutil.h index e990e4efa..f02c2a6b1 100644 --- a/src/include/ngspice/stringutil.h +++ b/src/include/ngspice/stringutil.h @@ -98,8 +98,6 @@ inline char *copy_substring(const char *str, const char *end) -/* Like scannum but *p_str is advanced past the number */ - /* Try to identify an unsigned integer that begins a string. Stop when a * non- numeric character is reached. There is no way to distinguish * between a value of 0 and a string that does not contain a numeric @@ -114,7 +112,7 @@ inline int scannum(const char *str) /* Determine whether sub is a substring of str. */ inline int substring(const char *sub, const char *str) { - return strstr(sub, str) != (char *) NULL; + return strstr(str, sub) != (char *) NULL; } /* end of function substring */ #ifdef CIDER diff --git a/src/misc/string.c b/src/misc/string.c index 8dfdfd734..7aaf87c03 100644 --- a/src/misc/string.c +++ b/src/misc/string.c @@ -236,7 +236,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 > INT_MAX) { + if (value - f_neg > (unsigned int) INT_MAX) { return -2; }