Memory access error: don't free GENinst->GENname.

Use memcpy to overwrite old name by a (shorter) new name.
Compiler warnings are thus removed.
This commit is contained in:
Holger Vogt 2021-12-14 14:57:59 +01:00
parent d741d61de8
commit 697cd0528e
1 changed files with 7 additions and 7 deletions

View File

@ -1132,15 +1132,15 @@ void modprobenames(INPtables* tab) {
GENinstance* GENinst; GENinstance* GENinst;
for (GENinst = tab->defVmod->GENinstances; GENinst; GENinst = GENinst->GENnextInstance) { for (GENinst = tab->defVmod->GENinstances; GENinst; GENinst = GENinst->GENnextInstance) {
char* name = GENinst->GENname; char* name = GENinst->GENname;
/* Do not inlude the x in the new name, XU1 -> U1 */
if (prefix("vcurr_x", name) && !isdigit_c(name[7])) { if (prefix("vcurr_x", name) && !isdigit_c(name[7])) {
/* copy from char no. 7 to (and excluding) second colon */ /* copy from char no. 7 to (and excluding) second colon */
char* endname = strchr(name, ':'); char* endname = strchr(name, ':');
endname = strchr(endname + 1, ':'); endname = strchr(endname + 1, ':');
char* newname = copy_substring(name + 7, endname); char* newname = copy_substring(name + 7, endname);
tfree(GENinst->GENname); memcpy(name, newname, strlen(newname) + 1);
GENinst->GENname = newname; tfree(newname);
} }
/* Do not inlude the x in the new name */
else if (prefix("vcurr_", name)) { else if (prefix("vcurr_", name)) {
/* copy from char no. 6 to (and excluding) second colon */ /* copy from char no. 6 to (and excluding) second colon */
char* endname = strchr(name, ':'); char* endname = strchr(name, ':');
@ -1148,14 +1148,14 @@ void modprobenames(INPtables* tab) {
/* two-terminal device, one colon, copy all from char no. 6 to (and excluding) colon */ /* two-terminal device, one colon, copy all from char no. 6 to (and excluding) colon */
if (!endname2) { if (!endname2) {
char* newname = copy_substring(name + 6, endname); char* newname = copy_substring(name + 6, endname);
tfree(GENinst->GENname); memcpy(name, newname, strlen(newname) + 1);
GENinst->GENname = newname; tfree(newname);
} }
/* copy from char no. 6 to (and excluding) second colon */ /* copy from char no. 6 to (and excluding) second colon */
else { else {
char* newname = copy_substring(name + 6, endname2); char* newname = copy_substring(name + 6, endname2);
tfree(GENinst->GENname); memcpy(name, newname, strlen(newname) + 1);
GENinst->GENname = newname; tfree(newname);
} }
} }
} }