diff --git a/nemu/src/monitor/sdb/watchpoint.c b/nemu/src/monitor/sdb/watchpoint.c index 0492c69..aca5238 100644 --- a/nemu/src/monitor/sdb/watchpoint.c +++ b/nemu/src/monitor/sdb/watchpoint.c @@ -76,13 +76,14 @@ int wp_add(char * expr) { tail->next = wp; tail = wp; } - int len = strlen(expr); + int len = strlen(expr) + 1; wp->expr = malloc(len * sizeof(char)); if (wp->expr == NULL) { Error("Failed to allocate memory for expression"); return 1; } - strncpy(wp->expr, expr, len - 1); + strncpy(wp->expr, expr, len); + wp->expr[len - 1] = '\0'; return 0; }