Skip to content

Commit 0f1c563

Browse files
committed
Minor style cleanups (NFC)
Reduces line change count by a little.
1 parent c6cc880 commit 0f1c563

File tree

1 file changed

+25
-32
lines changed

1 file changed

+25
-32
lines changed

Modules/binascii.c

Lines changed: 25 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -700,11 +700,10 @@ binascii_a2b_ascii85_impl(PyObject *module, Py_buffer *data, int fold_spaces,
700700
ascii_data[ascii_len - 2] != BASE85_A85_AFFIX ||
701701
ascii_data[ascii_len - 1] != BASE85_A85_SUFFIX) {
702702
state = get_binascii_state(module);
703-
if (state == NULL) {
704-
return NULL;
703+
if (state != NULL) {
704+
PyErr_SetString(state->Error,
705+
"Expected Ascii85 data to end with '~>'");
705706
}
706-
PyErr_SetString(state->Error,
707-
"Expected Ascii85 data to end with '~>'");
708707
return NULL;
709708
}
710709
ascii_len -= 2;
@@ -755,32 +754,29 @@ binascii_a2b_ascii85_impl(PyObject *module, Py_buffer *data, int fold_spaces,
755754
if (leftchar > UINT32_MAX / 85 ||
756755
(leftchar *= 85) > UINT32_MAX - this_digit) {
757756
state = get_binascii_state(module);
758-
if (state == NULL) {
759-
goto error_end;
757+
if (state != NULL) {
758+
PyErr_SetString(state->Error, "Ascii85 overflow");
760759
}
761-
PyErr_SetString(state->Error, "Ascii85 overflow");
762760
goto error_end;
763761
}
764762
leftchar += this_digit;
765763
group_pos++;
766764
} else if ((this_ch == 'y' && fold_spaces) || this_ch == 'z') {
767765
if (group_pos != 0) {
768766
state = get_binascii_state(module);
769-
if (state == NULL) {
770-
goto error_end;
767+
if (state != NULL) {
768+
PyErr_Format(state->Error,
769+
"'%c' inside Ascii85 5-tuple", this_ch);
771770
}
772-
PyErr_Format(state->Error,
773-
"'%c' inside Ascii85 5-tuple", this_ch);
774771
goto error_end;
775772
}
776773
leftchar = this_ch == 'y' ? BASE85_A85_Y : BASE85_A85_Z;
777774
group_pos = 5;
778775
} else if (!ignore_map[this_ch]) {
779776
state = get_binascii_state(module);
780-
if (state == NULL) {
781-
goto error_end;
777+
if (state != NULL) {
778+
PyErr_Format(state->Error, "'%c' invalid in Ascii85", this_ch);
782779
}
783-
PyErr_Format(state->Error, "'%c' invalid in Ascii85", this_ch);
784780
goto error_end;
785781
}
786782

@@ -792,10 +788,10 @@ binascii_a2b_ascii85_impl(PyObject *module, Py_buffer *data, int fold_spaces,
792788
/* Treat encoded length of 1 mod 5 as an error. */
793789
if (ascii_len == -3) {
794790
state = get_binascii_state(module);
795-
if (state == NULL) {
796-
goto error_end;
791+
if (state != NULL) {
792+
PyErr_SetString(state->Error,
793+
"Ascii85 data has invalid length");
797794
}
798-
PyErr_SetString(state->Error, "Ascii85 data has invalid length");
799795
goto error_end;
800796
}
801797

@@ -879,10 +875,9 @@ binascii_b2a_ascii85_impl(PyObject *module, Py_buffer *data, int fold_spaces,
879875

880876
for (; bin_len > 0 || chunk_pos != 0; bin_len--, bin_data++) {
881877
/* Shift data or padding into our buffer. */
878+
leftchar <<= 8; /* Pad with zero when encoding. */
882879
if (bin_len > 0) {
883-
leftchar = (leftchar << 8) | *bin_data;
884-
} else {
885-
leftchar <<= 8; /* Pad with zero when encoding. */
880+
leftchar |= *bin_data;
886881
}
887882

888883
/* Wait until buffer is full. */
@@ -986,22 +981,20 @@ binascii_a2b_base85_impl(PyObject *module, Py_buffer *data, int strict_mode,
986981
if (leftchar > UINT32_MAX / 85 ||
987982
(leftchar *= 85) > UINT32_MAX - this_digit) {
988983
state = get_binascii_state(module);
989-
if (state == NULL) {
990-
goto error_end;
984+
if (state != NULL) {
985+
PyErr_SetString(state->Error,
986+
z85 ? "z85 overflow" : "base85 overflow");
991987
}
992-
PyErr_SetString(state->Error,
993-
z85 ? "z85 overflow" : "base85 overflow");
994988
goto error_end;
995989
}
996990
leftchar += this_digit;
997991
group_pos++;
998992
} else if (strict_mode) {
999993
state = get_binascii_state(module);
1000-
if (state == NULL) {
1001-
goto error_end;
994+
if (state != NULL) {
995+
PyErr_Format(state->Error, "'%c' %s", this_ch,
996+
z85 ? "invalid in z85" : "invalid in base85");
1002997
}
1003-
PyErr_Format(state->Error, "'%c' %s", this_ch,
1004-
z85 ? "invalid in z85" : "invalid in base85");
1005998
goto error_end;
1006999
}
10071000

@@ -1013,11 +1006,11 @@ binascii_a2b_base85_impl(PyObject *module, Py_buffer *data, int strict_mode,
10131006
/* Treat encoded length of 1 mod 5 as an error. */
10141007
if (ascii_len == -3) {
10151008
state = get_binascii_state(module);
1016-
if (state == NULL) {
1017-
goto error_end;
1009+
if (state != NULL) {
1010+
PyErr_Format(state->Error,
1011+
z85 ? "z85 data has invalid length"
1012+
: "base85 data has invalid length");
10181013
}
1019-
PyErr_Format(state->Error, "%s data has invalid length",
1020-
z85 ? "z85" : "base85");
10211014
goto error_end;
10221015
}
10231016

0 commit comments

Comments
 (0)