@@ -700,11 +700,10 @@ binascii_a2b_ascii85_impl(PyObject *module, Py_buffer *data, int fold_spaces,
700
700
ascii_data [ascii_len - 2 ] != BASE85_A85_AFFIX ||
701
701
ascii_data [ascii_len - 1 ] != BASE85_A85_SUFFIX ) {
702
702
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 '~>'" );
705
706
}
706
- PyErr_SetString (state -> Error ,
707
- "Expected Ascii85 data to end with '~>'" );
708
707
return NULL ;
709
708
}
710
709
ascii_len -= 2 ;
@@ -755,32 +754,29 @@ binascii_a2b_ascii85_impl(PyObject *module, Py_buffer *data, int fold_spaces,
755
754
if (leftchar > UINT32_MAX / 85 ||
756
755
(leftchar *= 85 ) > UINT32_MAX - this_digit ) {
757
756
state = get_binascii_state (module );
758
- if (state = = NULL ) {
759
- goto error_end ;
757
+ if (state ! = NULL ) {
758
+ PyErr_SetString ( state -> Error , "Ascii85 overflow" ) ;
760
759
}
761
- PyErr_SetString (state -> Error , "Ascii85 overflow" );
762
760
goto error_end ;
763
761
}
764
762
leftchar += this_digit ;
765
763
group_pos ++ ;
766
764
} else if ((this_ch == 'y' && fold_spaces ) || this_ch == 'z' ) {
767
765
if (group_pos != 0 ) {
768
766
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 );
771
770
}
772
- PyErr_Format (state -> Error ,
773
- "'%c' inside Ascii85 5-tuple" , this_ch );
774
771
goto error_end ;
775
772
}
776
773
leftchar = this_ch == 'y' ? BASE85_A85_Y : BASE85_A85_Z ;
777
774
group_pos = 5 ;
778
775
} else if (!ignore_map [this_ch ]) {
779
776
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 ) ;
782
779
}
783
- PyErr_Format (state -> Error , "'%c' invalid in Ascii85" , this_ch );
784
780
goto error_end ;
785
781
}
786
782
@@ -792,10 +788,10 @@ binascii_a2b_ascii85_impl(PyObject *module, Py_buffer *data, int fold_spaces,
792
788
/* Treat encoded length of 1 mod 5 as an error. */
793
789
if (ascii_len == -3 ) {
794
790
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" );
797
794
}
798
- PyErr_SetString (state -> Error , "Ascii85 data has invalid length" );
799
795
goto error_end ;
800
796
}
801
797
@@ -879,10 +875,9 @@ binascii_b2a_ascii85_impl(PyObject *module, Py_buffer *data, int fold_spaces,
879
875
880
876
for (; bin_len > 0 || chunk_pos != 0 ; bin_len -- , bin_data ++ ) {
881
877
/* Shift data or padding into our buffer. */
878
+ leftchar <<= 8 ; /* Pad with zero when encoding. */
882
879
if (bin_len > 0 ) {
883
- leftchar = (leftchar << 8 ) | * bin_data ;
884
- } else {
885
- leftchar <<= 8 ; /* Pad with zero when encoding. */
880
+ leftchar |= * bin_data ;
886
881
}
887
882
888
883
/* Wait until buffer is full. */
@@ -986,22 +981,20 @@ binascii_a2b_base85_impl(PyObject *module, Py_buffer *data, int strict_mode,
986
981
if (leftchar > UINT32_MAX / 85 ||
987
982
(leftchar *= 85 ) > UINT32_MAX - this_digit ) {
988
983
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" );
991
987
}
992
- PyErr_SetString (state -> Error ,
993
- z85 ? "z85 overflow" : "base85 overflow" );
994
988
goto error_end ;
995
989
}
996
990
leftchar += this_digit ;
997
991
group_pos ++ ;
998
992
} else if (strict_mode ) {
999
993
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" );
1002
997
}
1003
- PyErr_Format (state -> Error , "'%c' %s" , this_ch ,
1004
- z85 ? "invalid in z85" : "invalid in base85" );
1005
998
goto error_end ;
1006
999
}
1007
1000
@@ -1013,11 +1006,11 @@ binascii_a2b_base85_impl(PyObject *module, Py_buffer *data, int strict_mode,
1013
1006
/* Treat encoded length of 1 mod 5 as an error. */
1014
1007
if (ascii_len == -3 ) {
1015
1008
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" );
1018
1013
}
1019
- PyErr_Format (state -> Error , "%s data has invalid length" ,
1020
- z85 ? "z85" : "base85" );
1021
1014
goto error_end ;
1022
1015
}
1023
1016
0 commit comments