> compile NEMU

ysyx_22040000 李心杨
Linux calcite 6.1.75 #1-NixOS SMP PREEMPT_DYNAMIC Thu Jan 25 23:27:52 UTC 2024 x86_64 GNU/Linux
 19:00:00  up 1 day  4:35,  2 users,  load average: 0.39, 0.65, 0.72
This commit is contained in:
tracer-ysyx 2024-02-08 19:00:00 +08:00 committed by xinyangli
parent 7b5f53a170
commit f4813afbdc

View file

@ -76,13 +76,13 @@ int wp_add(char * expr) {
tail->next = wp;
tail = wp;
}
int len = strlen(expr) + 1;
wp->expr = malloc(len * sizeof(char));
int len = strlen(expr);
wp->expr = malloc((len + 1) * sizeof(char));
if (wp->expr == NULL) {
Error("Failed to allocate memory for expression");
return 1;
}
strncpy(wp->expr, expr, len);
strncpy(wp->expr, expr, len + 1);
wp->expr[len - 1] = '\0';
return 0;
}