mirror of
https://git.code.sf.net/p/ngspice/ngspice
synced 2026-08-22 05:47:42 +02:00
misc/string.c: fix one byte ahead access in dup_string
In dup_string in misc/string.c , even if the destination buffer is allocated with n_char bytes, the source buffer `str` can be accessed up to only n_char bytes.
This commit is contained in:
+1
-1
@@ -78,7 +78,7 @@ char *dup_string(const char *str, size_t n_char)
|
|||||||
char *p = TMALLOC(char, n_char + 1);
|
char *p = TMALLOC(char, n_char + 1);
|
||||||
|
|
||||||
if (p != NULL) {
|
if (p != NULL) {
|
||||||
(void) memcpy(p, str, n_char + 1);
|
(void) memcpy(p, str, n_char);
|
||||||
p[n_char] = '\0';
|
p[n_char] = '\0';
|
||||||
}
|
}
|
||||||
return p;
|
return p;
|
||||||
|
|||||||
Reference in New Issue
Block a user