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

Commit3f4a78b

Browse files
committed
More tweaks
1 parent9f95672 commit3f4a78b

File tree

1 file changed

+7
-11
lines changed

1 file changed

+7
-11
lines changed

‎Modules/main.c‎

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -231,17 +231,15 @@ pymain_import_readline(const PyConfig *config)
231231

232232
// #define DEBUG_DEDENT
233233

234-
/* Strip common leading whitespace utf encoded string
235-
* returns a new PyBytes object that must be deallocated
236-
*/
234+
/* Strip common leading whitespace utf encoded string */
237235
PyObject*_utf_8_bytes_dedent(PyObject*bytes){
238-
char*input_data=PyBytes_AsString(bytes);
236+
char*input_data;
237+
Py_ssize_tnchars;
239238

240-
// Security problem? what is the right way to do this?
241-
Py_ssize_tnchars=strlen(input_data);
239+
PyBytes_AsStringAndSize(bytes,&input_data,&nchars);
242240

243-
// Allocate new data for the output
244-
PyBytesObject*new_bytes=PyBytes_FromStringAndSize(NULL,nchars);
241+
// Allocate new data for the output as a copy of the input
242+
PyBytesObject*new_bytes=PyBytes_FromStringAndSize(input_data,nchars);
245243
if (new_bytes==NULL) {
246244
returnNULL;
247245
}
@@ -255,13 +253,11 @@ PyObject* _utf_8_bytes_dedent(PyObject *bytes){
255253

256254
// Step 1: Find N = the common number leading whitespace chars
257255

258-
// Use the output array as a temporary buffer (because we haven't populated it yet)
259256
// so we can use the descructive strtok to tokenize the input.
260-
strcpy(new_data,input_data);
261-
262257
Py_ssize_tnum_common_leading_spaces=nchars+1;
263258

264259
// Count the number of leading spaces on each line
260+
// Use the output array as a temporary buffer (we will repopulate it later)
265261
char*line=strtok(new_data,"\n");
266262
while (line) {
267263
// Move the pointer up to the first non-space character

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp