Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitfd1444e

Browse files
vstinnermiss-islington
authored andcommitted
pythongh-71810: Fix _PyLong_AsByteArray() undefined behavior (pythonGH-138873)
Don't read p[-1] when p is an empty string: when n==0.(cherry picked from commit8b5ce31)Co-authored-by: Victor Stinner <vstinner@python.org>
1 parenta5f7e02 commitfd1444e

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

‎Objects/longobject.c‎

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1046,8 +1046,14 @@ _PyLong_AsByteArray(PyLongObject* v,
10461046
just above didn't get to ensure there's a sign bit, and the
10471047
loop below wouldn't add one either. Make sure a sign bit
10481048
exists. */
1049-
unsignedcharmsb=*(p-pincr);
1050-
intsign_bit_set=msb >=0x80;
1049+
intsign_bit_set;
1050+
if (n>0) {
1051+
unsignedcharmsb=*(p-pincr);
1052+
sign_bit_set=msb >=0x80;
1053+
}
1054+
else {
1055+
sign_bit_set=0;
1056+
}
10511057
assert(accumbits==0);
10521058
if (sign_bit_set==do_twos_comp)
10531059
return0;

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp