From 7dec3d7acbb072e0d5cd7357c1ddf12d3c667e8a Mon Sep 17 00:00:00 2001 From: Pablo Galindo Salgado Date: Fri, 23 Aug 2024 14:04:25 +0100 Subject: [PATCH] [3.12] gh-123229: Fix valgrind warning by initializing the f-string buffers to 0 in the tokenizer (GH-123263) (#123265) (cherry picked from commit adc5190014efcf7b7a4c5dfc9998faa8345527ed) Signed-off-by: Pablo Galindo --- .../2024-08-23-13-08-27.gh-issue-123229.aHm-dw.rst | 2 ++ Parser/tokenizer.c | 2 +- lel.patch | 13 +++++++++++++ 3 files changed, 16 insertions(+), 1 deletion(-) create mode 100644 Misc/NEWS.d/next/Core and Builtins/2024-08-23-13-08-27.gh-issue-123229.aHm-dw.rst create mode 100644 lel.patch diff --git a/Misc/NEWS.d/next/Core and Builtins/2024-08-23-13-08-27.gh-issue-123229.aHm-dw.rst b/Misc/NEWS.d/next/Core and Builtins/2024-08-23-13-08-27.gh-issue-123229.aHm-dw.rst new file mode 100644 index 00000000000000..aa9e8d1fa93bf5 --- /dev/null +++ b/Misc/NEWS.d/next/Core and Builtins/2024-08-23-13-08-27.gh-issue-123229.aHm-dw.rst @@ -0,0 +1,2 @@ +Fix valgrind warning by initializing the f-string buffers to 0 in the +tokenizer. Patch by Pablo Galindo diff --git a/Parser/tokenizer.c b/Parser/tokenizer.c index 3118fb19846578..9e0dee8cc383d6 100644 --- a/Parser/tokenizer.c +++ b/Parser/tokenizer.c @@ -65,7 +65,7 @@ static const char *type_comment_prefix = "# type: "; static struct tok_state *tok_new(void) { struct tok_state *tok = - (struct tok_state *)PyMem_Malloc(sizeof(struct tok_state)); + (struct tok_state *)PyMem_Calloc(1, sizeof(struct tok_state)); if (tok == NULL) return NULL; tok->buf = tok->cur = tok->inp = NULL; diff --git a/lel.patch b/lel.patch new file mode 100644 index 00000000000000..c525a7a00a9d2a --- /dev/null +++ b/lel.patch @@ -0,0 +1,13 @@ +diff --git a/Parser/tokenizer.c b/Parser/tokenizer.c +index 3118fb19846..9e0dee8cc38 100644 +--- a/Parser/tokenizer.c ++++ b/Parser/tokenizer.c +@@ -65,7 +65,7 @@ static const char *type_comment_prefix = "# type: "; + + static struct tok_state *tok_new(void) { + struct tok_state *tok = +- (struct tok_state *)PyMem_Malloc(sizeof(struct tok_state)); ++ (struct tok_state *)PyMem_Calloc(1, sizeof(struct tok_state)); + if (tok == NULL) + return NULL; + tok->buf = tok->cur = tok->inp = NULL;