@@ -237,7 +237,8 @@ static void pioneer_setup(int fd_create, const char *pgid_file) {
237237
238238 /* Reuse the previous run directory if it is still empty. */
239239 if (try_reuse_latest (serial_str )) {
240- (void )write (fd_create , serial_str , strlen (serial_str ));
240+ if (write (fd_create , serial_str , strlen (serial_str )) < 0 )
241+ goto failure ;
241242 close (fd_create );
242243 return ;
243244 }
@@ -249,20 +250,28 @@ static void pioneer_setup(int fd_create, const char *pgid_file) {
249250 if (n < 0 || n >= (int )sizeof (run_dir_storage ))
250251 break ;
251252 if (mkdir (run_dir_storage , 0777 ) == 0 ) {
252- snprintf (serial_str , sizeof (serial_str ), TEST_SERIAL_FMT , run_num );
253- (void )write (fd_create , serial_str , strlen (serial_str ));
253+ /* Use a larger buffer to avoid format-truncation: run_num is
254+ * bounded by TEST_SERIAL_MAX (1000000) so the output is always
255+ * TEST_SERIAL_LEN digits, but GCC sees the full int range. */
256+ char serial_buf [32 ];
257+ snprintf (serial_buf , sizeof (serial_buf ), TEST_SERIAL_FMT , run_num );
258+ memcpy (serial_str , serial_buf , TEST_SERIAL_LEN + 1 );
259+ if (write (fd_create , serial_str , strlen (serial_str )) < 0 )
260+ goto failure ;
254261 close (fd_create );
255262 char latest [PATH_MAX ];
256263 snprintf (latest , sizeof (latest ), TEMP_DIR "/latest" );
257264 unlink (latest );
258- symlink (serial_str , latest ); /* best-effort */
265+ int rc = symlink (serial_str , latest ); /* best-effort */
266+ (void )rc ;
259267 return ;
260268 }
261269 if (errno != EEXIST )
262270 break ;
263271 }
264272
265- /* Failed to create a run directory; clean up and fall back. */
273+ failure :
274+ /* Failed to create a run directory or write the serial; clean up. */
266275 run_dir_storage [0 ] = '\0' ;
267276 close (fd_create );
268277 unlink (pgid_file );
0 commit comments