bpo-40880: Fix invalid read in newline_in_string in pegen.c (GH-20666)
* bpo-40880: Fix invalid read in newline_in_string in pegen.c
* Update Parser/pegen/pegen.c
Co-authored-by: Lysandros Nikolaou <lisandrosnik@gmail.com>
* Add NEWS entry
Co-authored-by: Lysandros Nikolaou <lisandrosnik@gmail.com>
(cherry picked from commit 2e6593db0086004a1ca7f7049218ff9573d473c2)
Co-authored-by: Pablo Galindo <Pablogsal@gmail.com>
diff --git a/Parser/pegen/pegen.c b/Parser/pegen/pegen.c
index 6608fd8..76442de 100644
--- a/Parser/pegen/pegen.c
+++ b/Parser/pegen/pegen.c
@@ -936,8 +936,8 @@
static int // bool
newline_in_string(Parser *p, const char *cur)
{
- for (char c = *cur; cur >= p->tok->buf; c = *--cur) {
- if (c == '\'' || c == '"') {
+ for (const char *c = cur; c >= p->tok->buf; c--) {
+ if (*c == '\'' || *c == '"') {
return 1;
}
}