Skip to content

gh-121165: protect macro expansion of ADJUST_INDICES #121166

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jul 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 18 additions & 13 deletions Objects/bytes_methods.c
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
31 changes: 18 additions & 13 deletions Objects/unicodeobject.c
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
Loading