summaryrefslogtreecommitdiffstats
path: root/Objects
diff options
context:
space:
mode:
authorBénédikt Tran <10796600+picnixz@users.noreply.github.com>2024-07-02 10:57:51 (GMT)
committerGitHub <noreply@github.com>2024-07-02 10:57:51 (GMT)
commit6343486eb60ac5a9e15402a592298259c5afdee1 (patch)
tree7a7d258ad06a2ea0ace720b43b64f9f709b27385 /Objects
parent15232a0819a2f7e0f448f28f2e6081912d10e7cb (diff)
downloadcpython-6343486eb60ac5a9e15402a592298259c5afdee1.zip
cpython-6343486eb60ac5a9e15402a592298259c5afdee1.tar.gz
cpython-6343486eb60ac5a9e15402a592298259c5afdee1.tar.bz2
gh-121165: protect macro expansion of `ADJUST_INDICES` with do-while(0) (#121166)
Diffstat (limited to 'Objects')
-rw-r--r--Objects/bytes_methods.c31
-rw-r--r--Objects/unicodeobject.c31
2 files changed, 36 insertions, 26 deletions
diff --git a/Objects/bytes_methods.c b/Objects/bytes_methods.c
index 5525240..c239ae1 100644
--- a/Objects/bytes_methods.c
+++ b/Objects/bytes_methods.c
@@ -432,19 +432,24 @@ parse_args_finds_byte(const char *function_name, PyObject **subobj, char *byte)
}
/* helper macro to fixup start/end slice values */
-#define ADJUST_INDICES(start, end, len) \
- if (end > len) \
- end = len; \
- else if (end < 0) { \
- end += len; \
- if (end < 0) \
- end = 0; \
- } \
- if (start < 0) { \
- start += len; \
- if (start < 0) \
- start = 0; \
- }
+#define ADJUST_INDICES(start, end, len) \
+ do { \
+ if (end > len) { \
+ end = len; \
+ } \
+ else if (end < 0) { \
+ end += len; \
+ if (end < 0) { \
+ end = 0; \
+ } \
+ } \
+ if (start < 0) { \
+ start += len; \
+ if (start < 0) { \
+ start = 0; \
+ } \
+ } \
+ } while (0)
Py_LOCAL_INLINE(Py_ssize_t)
find_internal(const char *str, Py_ssize_t len,
diff --git a/Objects/unicodeobject.c b/Objects/unicodeobject.c
index 9738442..394ea88 100644
--- a/Objects/unicodeobject.c
+++ b/Objects/unicodeobject.c
@@ -9315,19 +9315,24 @@ _PyUnicode_TransformDecimalAndSpaceToASCII(PyObject *unicode)
/* --- Helpers ------------------------------------------------------------ */
/* helper macro to fixup start/end slice values */
-#define ADJUST_INDICES(start, end, len) \
- if (end > len) \
- end = len; \
- else if (end < 0) { \
- end += len; \
- if (end < 0) \
- end = 0; \
- } \
- if (start < 0) { \
- start += len; \
- if (start < 0) \
- start = 0; \
- }
+#define ADJUST_INDICES(start, end, len) \
+ do { \
+ if (end > len) { \
+ end = len; \
+ } \
+ else if (end < 0) { \
+ end += len; \
+ if (end < 0) { \
+ end = 0; \
+ } \
+ } \
+ if (start < 0) { \
+ start += len; \
+ if (start < 0) { \
+ start = 0; \
+ } \
+ } \
+ } while (0)
static Py_ssize_t
any_find_slice(PyObject* s1, PyObject* s2,