Skip to content

Commit 6929a4d

Browse files
committed
Move everthing to error labels
1 parent 95744bd commit 6929a4d

File tree

1 file changed

+9
-16
lines changed

1 file changed

+9
-16
lines changed

Objects/bytesobject.c

Lines changed: 9 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -2542,19 +2542,6 @@ _PyBytes_FromHex(PyObject *string, int use_bytearray)
25422542
}
25432543
str++;
25442544

2545-
/* Skip spaces after first digit */
2546-
while (str < end && Py_ISSPACE(*str)) {
2547-
str++;
2548-
}
2549-
2550-
/* Check if we have a second digit*/
2551-
if (str >= end) {
2552-
PyErr_SetString(PyExc_ValueError,
2553-
"fromhex() arg must be of even length");
2554-
_PyBytesWriter_Dealloc(&writer);
2555-
return NULL;
2556-
}
2557-
25582545
/* Check second hex digit */
25592546
bot = _PyLong_DigitValue[*str];
25602547
if (bot >= 16) {
@@ -2569,9 +2556,15 @@ _PyBytes_FromHex(PyObject *string, int use_bytearray)
25692556
return _PyBytesWriter_Finish(&writer, buf);
25702557

25712558
error:
2572-
PyErr_Format(PyExc_ValueError,
2573-
"non-hexadecimal number found in "
2574-
"fromhex() arg at position %zd", invalid_char);
2559+
if (str >= end) {
2560+
PyErr_SetString(PyExc_ValueError,
2561+
"fromhex() arg must be of even length");
2562+
}
2563+
else {
2564+
PyErr_Format(PyExc_ValueError,
2565+
"non-hexadecimal number found in "
2566+
"fromhex() arg at position %zd", invalid_char);
2567+
}
25752568
_PyBytesWriter_Dealloc(&writer);
25762569
return NULL;
25772570
}

0 commit comments

Comments
 (0)