From 79f772cee497ebd455a45a7f363edff5d1010fea Mon Sep 17 00:00:00 2001 From: wjc <2821296948@qq.com> Date: Mon, 12 Oct 2026 20:54:18 +0800 Subject: [PATCH] fix: allocate longest palindrome result by length Co-Authored-By: chaogeshuodiannao --- leetcode/src/5.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/leetcode/src/5.c b/leetcode/src/5.c index e54bf598da..4572a90dbb 100644 --- a/leetcode/src/5.c +++ b/leetcode/src/5.c @@ -42,7 +42,7 @@ char * longestPalindrome(char * s) { } } - if ((s_longest = (char *) malloc(sizeof(s))) == NULL) { + if ((s_longest = malloc((size_t)sz_max + 1)) == NULL) { return NULL; } strncpy(s_longest, s + si_max, sz_max);