@@ -180,8 +180,9 @@ parse_internal_render_format_spec(STRINGLIB_CHAR *format_spec,
180180
181181 Py_ssize_t consumed ;
182182 int align_specified = 0 ;
183+ int fill_char_specified = 0 ;
183184
184- format -> fill_char = '\0 ' ;
185+ format -> fill_char = ' ' ;
185186 format -> align = default_align ;
186187 format -> alternate = 0 ;
187188 format -> sign = '\0' ;
@@ -195,6 +196,7 @@ parse_internal_render_format_spec(STRINGLIB_CHAR *format_spec,
195196 if (end - ptr >= 2 && is_alignment_token (ptr [1 ])) {
196197 format -> align = ptr [1 ];
197198 format -> fill_char = ptr [0 ];
199+ fill_char_specified = 1 ;
198200 align_specified = 1 ;
199201 ptr += 2 ;
200202 }
@@ -218,7 +220,7 @@ parse_internal_render_format_spec(STRINGLIB_CHAR *format_spec,
218220 }
219221
220222 /* The special case for 0-padding (backwards compat) */
221- if (format -> fill_char == '\0' && end - ptr >= 1 && ptr [0 ] == '0' ) {
223+ if (! fill_char_specified && end - ptr >= 1 && ptr [0 ] == '0' ) {
222224 format -> fill_char = '0' ;
223225 if (!align_specified ) {
224226 format -> align = '=' ;
@@ -715,8 +717,7 @@ format_string_internal(PyObject *value, const InternalFormatSpec *format)
715717
716718 /* Write into that space. First the padding. */
717719 p = fill_padding (STRINGLIB_STR (result ), len ,
718- format -> fill_char == '\0' ?' ' :format -> fill_char ,
719- lpad , rpad );
720+ format -> fill_char , lpad , rpad );
720721
721722 /* Then the source string. */
722723 memcpy (p , STRINGLIB_STR (value ), len * sizeof (STRINGLIB_CHAR ));
@@ -893,8 +894,7 @@ format_int_or_long_internal(PyObject *value, const InternalFormatSpec *format,
893894
894895 /* Populate the memory. */
895896 fill_number (STRINGLIB_STR (result ), & spec , pnumeric_chars , n_digits ,
896- prefix , format -> fill_char == '\0' ? ' ' : format -> fill_char ,
897- & locale , format -> type == 'X' );
897+ prefix , format -> fill_char , & locale , format -> type == 'X' );
898898
899899done :
900900 Py_XDECREF (tmp );
@@ -1048,8 +1048,7 @@ format_float_internal(PyObject *value,
10481048
10491049 /* Populate the memory. */
10501050 fill_number (STRINGLIB_STR (result ), & spec , p , n_digits , NULL ,
1051- format -> fill_char == '\0' ? ' ' : format -> fill_char , & locale ,
1052- 0 );
1051+ format -> fill_char , & locale , 0 );
10531052
10541053done :
10551054 PyMem_Free (buf );
@@ -1265,8 +1264,7 @@ format_complex_internal(PyObject *value,
12651264 /* Populate the memory. First, the padding. */
12661265 p = fill_padding (STRINGLIB_STR (result ),
12671266 n_re_total + n_im_total + 1 + add_parens * 2 ,
1268- format -> fill_char == '\0' ? ' ' : format -> fill_char ,
1269- lpad , rpad );
1267+ format -> fill_char , lpad , rpad );
12701268
12711269 if (add_parens )
12721270 * p ++ = '(' ;
0 commit comments