Просмотр исходного кода

Use size_t and %zu to handle memory sizes and offsets

Guillem Jover лет назад: 15
Родитель
Сommit
74dc50b34d
4 измененных файлов с 9 добавлено и 7 удалено
  1. 3 3
      dselect/methparse.cc
  2. 4 2
      lib/dpkg/mlib.c
  3. 1 1
      lib/dpkg/pkg-format.c
  4. 1 1
      utils/update-alternatives.c

+ 3 - 3
dselect/methparse.cc

@@ -193,7 +193,7 @@ void readmethods(const char *pathbase, dselect_option **optionspp, int *nread) {
         if (fstat(fileno(descfile),&stab))
           ohshite(_("unable to stat option description file `%.250s'"),pathbuf);
         opt->description= new char[stab.st_size+1];  errno=0;
-        unsigned long filelen= stab.st_size;
+        size_t filelen = stab.st_size;
         if (fread(opt->description,1,stab.st_size+1,descfile) != filelen)
           ohshite(_("failed to read option description file `%.250s'"),pathbuf);
         opt->description[stab.st_size]= 0;
@@ -205,12 +205,12 @@ void readmethods(const char *pathbase, dselect_option **optionspp, int *nread) {
 
       debug(dbg_general,
             " readmethods('%s',...) new option index='%s' name='%s'"
-            " summary='%.20s' strlen(description=%s)=%ld method name='%s'"
+            " summary='%.20s' strlen(description=%s)=%zu method name='%s'"
             " path='%s' pathinmeth='%s'",
             pathbase,
             opt->index, opt->name, opt->summary,
             opt->description ? "'...'" : "null",
-            opt->description ? (long)strlen(opt->description) : -1,
+            opt->description ? strlen(opt->description) : -1,
             opt->meth->name, opt->meth->path, opt->meth->pathinmeth);
 
       dselect_option **optinsert = optionspp;

+ 4 - 2
lib/dpkg/mlib.c

@@ -40,7 +40,8 @@ void *m_malloc(size_t amount) {
 
   onerr_abort++;
   r= malloc(amount);
-  if (!r) ohshite(_("malloc failed (%ld bytes)"),(long)amount);
+  if (r == NULL)
+    ohshite(_("malloc failed (%zu bytes)"), amount);
   onerr_abort--;
 
 #ifdef MDEBUG
@@ -53,7 +54,8 @@ void *m_malloc(size_t amount) {
 void *m_realloc(void *r, size_t amount) {
   onerr_abort++;
   r= realloc(r,amount);
-  if (!r) ohshite(_("realloc failed (%ld bytes)"),(long)amount);
+  if (r == NULL)
+    ohshite(_("realloc failed (%zu bytes)"), amount);
   onerr_abort--;
 
   return r;

+ 1 - 1
lib/dpkg/pkg-format.c

@@ -213,7 +213,7 @@ pkg_format_show(const struct pkg_format_node *head,
 		ok = false;
 
 		if (head->width > 0)
-			snprintf(fmt, 16, "%%%s%zds",
+			snprintf(fmt, 16, "%%%s%zus",
 			         ((head->pad) ? "-" : ""), head->width);
 		else
 			strcpy(fmt, "%s");

+ 1 - 1
utils/update-alternatives.c

@@ -246,7 +246,7 @@ xmalloc(size_t size)
 
 	r = malloc(size);
 	if (!r)
-		error(_("malloc failed (%ld bytes)"), (long)size);
+		error(_("malloc failed (%zu bytes)"), size);
 
 	return r;
 }