]> Savannah Git Hosting - gnulib.git/commitdiff
backupfile: prefer signed integers
authorPaul Eggert <eggert@cs.ucla.edu>
Fri, 10 Dec 2021 21:43:10 +0000 (13:43 -0800)
committerPaul Eggert <eggert@cs.ucla.edu>
Fri, 10 Dec 2021 21:57:35 +0000 (13:57 -0800)
* lib/backupfile.c: Include ialloc.h instead of idx.h.
Prefer idx_t to size_t where either will do.
Use imalloc and irealloc instead of malloc and realloc.
* modules/backupfile, modules/backup-rename (Depends-on):
Depend on ialloc not idx.

ChangeLog
lib/backupfile.c
modules/backup-rename
modules/backupfile

index d012fb9488e0ddcf0a05aa479b585d5afc2cc63c..bb69d3246d77c193786d3f0dee7b1da7bf3a04e7 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,12 @@
 2021-12-10  Paul Eggert  <eggert@cs.ucla.edu>
 
+       backupfile: prefer signed integers
+       * lib/backupfile.c: Include ialloc.h instead of idx.h.
+       Prefer idx_t to size_t where either will do.
+       Use imalloc and irealloc instead of malloc and realloc.
+       * modules/backupfile, modules/backup-rename (Depends-on):
+       Depend on ialloc not idx.
+
        backupfile: fix numbered backups for XXX/
        * lib/backupfile.c (check_extension): Return a bool indicating
        whether the original extension was OK.  Caller changed.
index 488eecfd8244a2ea3383fa7eac38499fc94569e4..6667fd822f27f05c0be67163eebc13bac71fa187 100644 (file)
@@ -33,7 +33,7 @@
 
 #include "attribute.h"
 #include "basename-lgpl.h"
-#include "idx.h"
+#include "ialloc.h"
 #include "intprops.h"
 #include "opendirat.h"
 #include "renameatu.h"
@@ -99,12 +99,12 @@ set_simple_backup_suffix (char const *s)
    FILE's parent's _PC_NAME_MAX.  */
 
 static bool
-check_extension (char *file, size_t filelen, char e,
-                 int dir_fd, size_t *base_max)
+check_extension (char *file, idx_t filelen, char e,
+                 int dir_fd, idx_t *base_max)
 {
   char *base = last_component (file);
-  size_t baselen = base_len (base);
-  size_t baselen_max = HAVE_LONG_FILE_NAMES ? 255 : NAME_MAX_MINIMUM;
+  idx_t baselen = base_len (base);
+  idx_t baselen_max = HAVE_LONG_FILE_NAMES ? 255 : NAME_MAX_MINIMUM;
 
   if (HAVE_DOS_FILE_NAMES || NAME_MAX_MINIMUM < baselen)
     {
@@ -206,16 +206,16 @@ enum numbered_backup_result
    and its file descriptor into *PNEW_FD without closing the stream.  */
 
 static enum numbered_backup_result
-numbered_backup (int dir_fd, char **buffer, size_t buffer_size, size_t filelen,
+numbered_backup (int dir_fd, char **buffer, idx_t buffer_size, idx_t filelen,
                  idx_t base_offset, DIR **dirpp, int *pnew_fd)
 {
   enum numbered_backup_result result = BACKUP_IS_NEW;
   DIR *dirp = *dirpp;
   struct dirent *dp;
   char *buf = *buffer;
-  size_t versionlenmax = 1;
+  idx_t versionlenmax = 1;
   char *base = buf + base_offset;
-  size_t baselen = filelen - base_offset;
+  idx_t baselen = filelen - base_offset;
 
   if (dirp)
     rewinddir (dirp);
@@ -241,7 +241,7 @@ numbered_backup (int dir_fd, char **buffer, size_t buffer_size, size_t filelen,
       char const *p;
       char *q;
       bool all_9s;
-      size_t versionlen;
+      idx_t versionlen;
 
       if (_D_EXACT_NAMLEN (dp) < baselen + 4)
         continue;
@@ -273,13 +273,13 @@ numbered_backup (int dir_fd, char **buffer, size_t buffer_size, size_t filelen,
 
       versionlenmax = all_9s + versionlen;
       result = (all_9s ? BACKUP_IS_LONGER : BACKUP_IS_SAME_LENGTH);
-      size_t new_buffer_size = filelen + 2 + versionlenmax + 2;
+      idx_t new_buffer_size = filelen + 2 + versionlenmax + 2;
       if (buffer_size < new_buffer_size)
         {
-          size_t grown;
+          idx_t grown;
           if (! INT_ADD_WRAPV (new_buffer_size, new_buffer_size >> 1, &grown))
             new_buffer_size = grown;
-          char *new_buf = realloc (buf, new_buffer_size);
+          char *new_buf = irealloc (buf, new_buffer_size);
           if (!new_buf)
             {
               *buffer = buf;
@@ -318,27 +318,27 @@ backupfile_internal (int dir_fd, char const *file,
                      enum backup_type backup_type, bool rename)
 {
   idx_t base_offset = last_component (file) - file;
-  size_t filelen = base_offset + base_len (file + base_offset);
+  idx_t filelen = base_offset + base_len (file + base_offset);
 
   if (! simple_backup_suffix)
     set_simple_backup_suffix (NULL);
 
   /* Allow room for simple or ".~N~" backups.  The guess must be at
      least sizeof ".~1~", but otherwise will be adjusted as needed.  */
-  size_t simple_backup_suffix_size = strlen (simple_backup_suffix) + 1;
-  size_t backup_suffix_size_guess = simple_backup_suffix_size;
+  idx_t simple_backup_suffix_size = strlen (simple_backup_suffix) + 1;
+  idx_t backup_suffix_size_guess = simple_backup_suffix_size;
   enum { GUESS = sizeof ".~12345~" };
   if (backup_suffix_size_guess < GUESS)
     backup_suffix_size_guess = GUESS;
 
-  ssize_t ssize = filelen + backup_suffix_size_guess + 1;
-  char *s = malloc (ssize);
+  idx_t ssize = filelen + backup_suffix_size_guess + 1;
+  char *s = imalloc (ssize);
   if (!s)
     return s;
 
   DIR *dirp = NULL;
   int sdir = -1;
-  size_t base_max = 0;
+  idx_t base_max = 0;
   while (true)
     {
       bool extended = true;
index c50e874ff88bbb094f17d8bacb714e6dc913b53d..245350a4df753461d04a0a05f9b54a3d20a02941 100644 (file)
@@ -16,7 +16,7 @@ c99
 closedir
 d-ino
 fcntl-h
-idx
+ialloc
 intprops
 memcmp
 opendirat
index 342a7bdff1bdf88584e9e0faf7dd98524db1948f..3d06da9ed4073db6354ce856ce183f65585bb521 100644 (file)
@@ -16,7 +16,7 @@ c99
 closedir
 d-ino
 fcntl-h
-idx
+ialloc
 intprops
 memcmp
 opendirat