@@ -222,37 +222,40 @@ faulthandler_stack_dump_impl(int fd)
222222{
223223#define BACKTRACE_SIZE 128
224224#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 );
228228 if (strings == NULL ) {
229229 PUTS (fd , " <failed to get stack trace>" );
230230 }
231231 else {
232232 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 ]);
235235 size_t length = strlen (entry_str ) + 1 ;
236- if (length == ENTRY_SIZE )
237- {
236+ if (length == TRACEBACK_ENTRY_MAX_SIZE ) {
238237 /* We exceeded the size, make it look prettier */
239238
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' ;
243246
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' ;
246249 }
247250 _Py_write_noraise (fd , entry_str , length );
248251 }
249252
250- if (frames == SIZE ) {
253+ if (frames == BACKTRACE_SIZE ) {
251254 PUTS (fd , " <truncated rest of calls>" );
252255 }
253256 }
254- #undef ENTRY_SIZE
255- #undef SIZE
257+ #undef BACKTRACE_SIZE
258+ #undef TRACEBACK_ENTRY_MAX_SIZE
256259}
257260#else
258261static void
0 commit comments