Skip to content

Commit

Permalink
[YottaDB#264] Zero pad the hexadecimal pid in the backup temporary fi…
Browse files Browse the repository at this point in the history
…le name to keep its length at 4-bytes even if the process_id is less than 2**24
  • Loading branch information
nars1 committed Jun 1, 2018
1 parent 5015093 commit 7833fd4
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions sr_port/mupip_backup.c
Original file line number Diff line number Diff line change
Expand Up @@ -610,8 +610,12 @@ void mupip_backup(void)
mubclnup(rptr, need_to_del_tempfile);
mupip_exit(ustatus);
}
/* Creating temp filename here. Check if we have the required space. */
nbytes = SNPRINTF(tempfilename, SIZEOF(tempfilename), "%.*s/%.*s_%4x_XXXXXX",
/* Creating temp filename here. Check if we have the required space.
* Use %04x (instead of %x) for process_id to ensure we have 4 bytes always even if process_id
* is a small number (< 2**24 etc.) and is 0-filled on the left if needed. Makes the length
* deterministic instead of being dependent on the process_id.
*/
nbytes = SNPRINTF(tempfilename, SIZEOF(tempfilename), "%.*s/%.*s_%04x_XXXXXX",
tempdir_full.len, tempdir_full.addr, gv_cur_region->rname_len, gv_cur_region->rname, process_id);
if ((0 > nbytes) || (nbytes >= SIZEOF(tempfilename)))
{ /* Error return from SNPRINTF */
Expand Down

0 comments on commit 7833fd4

Please sign in to comment.