summaryrefslogtreecommitdiffstats
path: root/Objects
diff options
context:
space:
mode:
authorPablo Galindo Salgado <Pablogsal@gmail.com>2022-06-28 13:24:54 (GMT)
committerGitHub <noreply@github.com>2022-06-28 13:24:54 (GMT)
commitc485ec014ce174bb3f5ae948151dc40e0f6d5f7f (patch)
tree00bd42a4845896a0ed60555bdc5f85c3a870246c /Objects
parent44fa03d748eb2b9a13a77c6143b18968521a1980 (diff)
downloadcpython-c485ec014ce174bb3f5ae948151dc40e0f6d5f7f.zip
cpython-c485ec014ce174bb3f5ae948151dc40e0f6d5f7f.tar.gz
cpython-c485ec014ce174bb3f5ae948151dc40e0f6d5f7f.tar.bz2
gh-88116: Avoid undefined behavior when decoding varints in code objects (#94375)
Diffstat (limited to 'Objects')
-rw-r--r--Objects/codeobject.c16
1 files changed, 8 insertions, 8 deletions
diff --git a/Objects/codeobject.c b/Objects/codeobject.c
index c38c51b..6f2a837 100644
--- a/Objects/codeobject.c
+++ b/Objects/codeobject.c
@@ -354,9 +354,9 @@ init_code(PyCodeObject *co, struct _PyCodeConstructor *con)
static int
scan_varint(const uint8_t *ptr)
{
- int read = *ptr++;
- int val = read & 63;
- int shift = 0;
+ unsigned int read = *ptr++;
+ unsigned int val = read & 63;
+ unsigned int shift = 0;
while (read & 64) {
read = *ptr++;
shift += 6;
@@ -368,7 +368,7 @@ scan_varint(const uint8_t *ptr)
static int
scan_signed_varint(const uint8_t *ptr)
{
- int uval = scan_varint(ptr);
+ unsigned int uval = scan_varint(ptr);
if (uval & 1) {
return -(int)(uval >> 1);
}
@@ -847,9 +847,9 @@ read_byte(PyCodeAddressRange *bounds)
static int
read_varint(PyCodeAddressRange *bounds)
{
- int read = read_byte(bounds);
- int val = read & 63;
- int shift = 0;
+ unsigned int read = read_byte(bounds);
+ unsigned int val = read & 63;
+ unsigned int shift = 0;
while (read & 64) {
read = read_byte(bounds);
shift += 6;
@@ -861,7 +861,7 @@ read_varint(PyCodeAddressRange *bounds)
static int
read_signed_varint(PyCodeAddressRange *bounds)
{
- int uval = read_varint(bounds);
+ unsigned int uval = read_varint(bounds);
if (uval & 1) {
return -(int)(uval >> 1);
}