@@ -222,37 +222,40 @@ faulthandler_stack_dump_impl(int fd)
222
222
{
223
223
#define BACKTRACE_SIZE 128
224
224
#define TRACEBACK_ENTRY_MAX_SIZE 256
225
- void * callstack [SIZE ];
226
- int frames = backtrace (callstack , SIZE );
227
- char * * strings = backtrace_symbols (callstack , SIZE );
225
+ void * callstack [BACKTRACE_SIZE ];
226
+ int frames = backtrace (callstack , BACKTRACE_SIZE );
227
+ char * * strings = backtrace_symbols (callstack , BACKTRACE_SIZE );
228
228
if (strings == NULL ) {
229
229
PUTS (fd , " <failed to get stack trace>" );
230
230
}
231
231
else {
232
232
for (int i = 0 ; i < frames ; ++ i ) {
233
- char entry_str [ENTRY_SIZE ];
234
- snprintf (entry_str , ENTRY_SIZE , " %s\n" , strings [i ]);
233
+ char entry_str [TRACEBACK_ENTRY_MAX_SIZE ];
234
+ snprintf (entry_str , TRACEBACK_ENTRY_MAX_SIZE , " %s\n" , strings [i ]);
235
235
size_t length = strlen (entry_str ) + 1 ;
236
- if (length == ENTRY_SIZE )
237
- {
236
+ if (length == TRACEBACK_ENTRY_MAX_SIZE ) {
238
237
/* We exceeded the size, make it look prettier */
239
238
240
- // Add ellipsis to last 3 characters (but before the newline and null terminator)
241
- for (int x = 0 ; x < 3 ; ++ x )
242
- entry_str [ENTRY_SIZE - (x + 3 )] = '.' ;
239
+ // Add ellipsis to last 3 characters
240
+ entry_str [TRACEBACK_ENTRY_MAX_SIZE - 5 ] = '.' ;
241
+ entry_str [TRACEBACK_ENTRY_MAX_SIZE - 4 ] = '.' ;
242
+ entry_str [TRACEBACK_ENTRY_MAX_SIZE - 3 ] = '.' ;
243
+
244
+ // Ensure trailing newline
245
+ entry_str [TRACEBACK_ENTRY_MAX_SIZE - 2 ] = '\n' ;
243
246
244
- entry_str [ ENTRY_SIZE - 2 ] = '\n' ;
245
- entry_str [ENTRY_SIZE - 1 ] = '\0' ;
247
+ // Ensure that it's null-terminated
248
+ entry_str [TRACEBACK_ENTRY_MAX_SIZE - 1 ] = '\0' ;
246
249
}
247
250
_Py_write_noraise (fd , entry_str , length );
248
251
}
249
252
250
- if (frames == SIZE ) {
253
+ if (frames == BACKTRACE_SIZE ) {
251
254
PUTS (fd , " <truncated rest of calls>" );
252
255
}
253
256
}
254
- #undef ENTRY_SIZE
255
- #undef SIZE
257
+ #undef BACKTRACE_SIZE
258
+ #undef TRACEBACK_ENTRY_MAX_SIZE
256
259
}
257
260
#else
258
261
static void
0 commit comments