ソースを参照

Use m_malloc instead of malloc

Guillem Jover 18 年 前
コミット
ffe852d215
共有10 個のファイルを変更した41 個の追加46 個の削除を含む
  1. 17 0
      ChangeLog
  2. 3 3
      dpkg-deb/build.c
  3. 1 3
      dpkg-deb/extract.c
  4. 5 4
      lib/mlib.c
  5. 2 4
      lib/myopt.c
  6. 1 2
      lib/parse.c
  7. 3 3
      lib/showpkg.c
  8. 5 15
      lib/tarfn.c
  9. 1 1
      src/archives.c
  10. 3 11
      src/main.c

+ 17 - 0
ChangeLog

@@ -1,3 +1,20 @@
+2008-01-21  Guillem Jover  <guillem@debian.org>
+
+	* dpkg-deb/build.c (getfi): Use m_malloc instead of malloc.
+	(do_build): Likewise.
+	* dpkg-deb/extract.c (extracthalf): Likewise.
+	* lib/mlib.c (buffer_write): Likewise.
+	(buffer_copy): Likewise.
+	* lib/myopt.c (loadcfgfile): Likewise.
+	* lib/parse.c (parsedb): Likewise.
+	* lib/showpkg.c (alloclstitem): Likewise.
+	(parsefield): Likewise.
+	(parsestring): Likewise.
+	* lib/tarfn.c (StoC): Likewise.
+	(TarExtractor): Likewise.
+	* src/archives.c (try_deconfigure_can): Likewise.
+	* src/main.c (execbackend): Likewise.
+
 2008-01-21  Guillem Jover  <guillem@debian.org>
 
 	* lib/mlib.c (m_strdup): New function.

+ 3 - 3
dpkg-deb/build.c

@@ -101,7 +101,7 @@ static struct _finfo* getfi(const char* root, int fd) {
 
   if (fn == NULL) {
     fnlen = rl + MAXFILENAME;
-    fn=(char*)malloc(fnlen);
+    fn = m_malloc(fnlen);
   } else if (fnlen < (rl + MAXFILENAME)) {
     fnlen = rl + MAXFILENAME;
     fn=(char*)realloc(fn,fnlen);
@@ -131,7 +131,7 @@ static struct _finfo* getfi(const char* root, int fd) {
       ohshit(_("file name '%.50s...' is too long"), fn + rl + 1);
   }
 
-  fi=(struct _finfo*)malloc(sizeof(struct _finfo));
+  fi = m_malloc(sizeof(struct _finfo));
   lstat(fn, &(fi->st));
   fi->fn = m_strdup(fn + rl + 1);
   fi->next=NULL;
@@ -193,7 +193,7 @@ void do_build(const char *const *argv) {
   /* template for our tempfiles */
   if ((envbuf= getenv("TMPDIR")) == NULL)
     envbuf= P_tmpdir;
-  tfbuf = (char *)malloc(strlen(envbuf)+13);
+  tfbuf = m_malloc(strlen(envbuf) + 13);
   strcpy(tfbuf,envbuf);
   strcat(tfbuf,"/dpkg.XXXXXX");
   subdir= 0;

+ 1 - 3
dpkg-deb/extract.c

@@ -210,9 +210,7 @@ void extracthalf(const char *debar, const char *directory,
                  (long) (stab.st_size - ctrllennum - strlen(ctrllenbuf) - l)) == EOF ||
           fflush(stdout)) werr("stdout");
     
-    ctrlarea = malloc(ctrllennum);
-    if (!ctrlarea)
-      ohshite(_("failed allocating memory for variable `ctrlarea'"));
+    ctrlarea = m_malloc(ctrllennum);
 
     errno=0; if (fread(ctrlarea,1,ctrllennum,ar) != ctrllennum)
       readfail(ar, debar, _("control area"));

+ 5 - 4
lib/mlib.c

@@ -171,7 +171,9 @@ off_t buffer_write(buffer_data_t data, void *buf, off_t length, const char *desc
     switch(data->type ^ BUFFER_WRITE_SETUP) {
       case BUFFER_WRITE_MD5:
 	{
-	  struct buffer_write_md5ctx *ctx = malloc(sizeof(struct buffer_write_md5ctx));
+	  struct buffer_write_md5ctx *ctx;
+
+	  ctx = m_malloc(sizeof(struct buffer_write_md5ctx));
 	  ctx->hash = data->data.ptr;
 	  data->data.ptr = ctx;
 	  MD5Init(&ctx->ctx);
@@ -187,7 +189,7 @@ off_t buffer_write(buffer_data_t data, void *buf, off_t length, const char *desc
 	  int i;
 	  unsigned char digest[16], *p = digest;
 	  struct buffer_write_md5ctx *ctx = (struct buffer_write_md5ctx *)data->data.ptr;
-	  unsigned char *hash = *ctx->hash = malloc(33);
+	  unsigned char *hash = *ctx->hash = m_malloc(33);
 	  MD5Final(digest, &ctx->ctx);
 	  for (i = 0; i < 16; ++i) {
 	    sprintf((char *)hash, "%02x", *p++);
@@ -316,8 +318,7 @@ off_t buffer_copy(buffer_data_t read_data, buffer_data_t write_data, off_t limit
   if((limit!=-1) && (limit < bufsize)) bufsize= limit;
   if(bufsize == 0)
     return 0;
-  writebuf= buf= malloc(bufsize);
-  if(buf== NULL) ohshite(_("failed to allocate buffer in buffer_copy (%s)"), desc);
+  writebuf = buf= m_malloc(bufsize);
 
   while(bytesread >= 0 && byteswritten >= 0 && bufsize > 0) {
     bytesread= read_data->proc(read_data, buf, bufsize, desc);

+ 2 - 4
lib/myopt.c

@@ -91,16 +91,14 @@ void loadcfgfile(const char *prog, const struct cmdinfo* cmdinfos) {
   char *home, *file;
   int l1, l2;
   l1 = strlen(CONFIGDIR "/.cfg") + strlen(prog);
-  file = malloc(l1 + 1);
-  if (file==NULL) ohshite(_("Error allocating memory for cfgfilename"));
+  file = m_malloc(l1 + 1);
   sprintf(file, CONFIGDIR "/%s.cfg", prog);
   myfileopt(file, cmdinfos);
   if ((home = getenv("HOME")) != NULL) {
     l2 = strlen(home) + 1 + strlen("/.cfg") + strlen(prog);
     if (l2 > l1) {
       free(file);
-      file = malloc(l2 + 1);
-      if (file==NULL) ohshite(_("Error allocating memory for cfgfilename"));
+      file = m_malloc(l2 + 1);
     }
     sprintf(file, "%s/.%s.cfg", home, prog);
     myfileopt(file, cmdinfos);

+ 1 - 2
lib/parse.c

@@ -115,8 +115,7 @@ int parsedb(const char *filename, enum parsedbflags flags,
     if ((dataptr= (char *)mmap(NULL, stat.st_size, PROT_READ, MAP_SHARED, fd, 0)) == MAP_FAILED)
       ohshite(_("can't mmap package info file `%.255s'"),filename);
 #else
-    if ((dataptr= malloc(stat.st_size)) == NULL)
-      ohshite(_("failed to malloc for info file `%.255s'"),filename);
+    dataptr = m_malloc(stat.st_size);
 
     fd_buf_copy(fd, dataptr, stat.st_size, _("copy info file `%.255s'"),filename);
 #endif

+ 3 - 3
lib/showpkg.c

@@ -43,7 +43,7 @@ struct lstitem {
 static struct lstitem* alloclstitem(void) {
 	struct lstitem*	buf;
 
-	buf=(struct lstitem*)malloc(sizeof(struct lstitem));
+	buf = m_malloc(sizeof(struct lstitem));
 	buf->type=invalid;
 	buf->next=NULL;
 	buf->data=NULL;
@@ -81,7 +81,7 @@ static int parsefield(struct lstitem* cur, const char* fmt, const char* fmtend)
 	}
 
 	cur->type=field;
-	cur->data=(char*)malloc(len+1);
+	cur->data = m_malloc(len + 1);
 	memcpy(cur->data, fmt, len);
 	cur->data[len]='\0';
 
@@ -96,7 +96,7 @@ static int parsestring(struct lstitem* cur, const char* fmt, const char* fmtend)
 	len=fmtend-fmt+1;
 
 	cur->type=string;
-	write=cur->data=(char*)malloc(len+1);
+	write = cur->data = m_malloc(len + 1);
 	while (fmt<=fmtend) {
 		if (*fmt=='\\') {
 			fmt++;

+ 5 - 15
lib/tarfn.c

@@ -62,7 +62,7 @@ StoC(const char *s, int size)
 	char *	str;
 
 	len = strnlen(s, size);
-	str = malloc(len + 1);
+	str = m_malloc(len + 1);
 	memcpy(str, s, len);
 	str[len] = 0;
 
@@ -138,7 +138,7 @@ TarExtractor(
        next_long_name = NULL;
        next_long_link = NULL;
        long_read = 0;
-	symListBottom = symListPointer = symListTop = malloc(sizeof(symlinkList));
+	symListBottom = symListPointer = symListTop = m_malloc(sizeof(symlinkList));
 	symListTop->next = NULL;
 
 	h.UserData = userData;
@@ -198,13 +198,8 @@ TarExtractor(
 			memcpy(&symListBottom->h, &h, sizeof(TarInfo));
 			symListBottom->h.Name = m_strdup(h.Name);
 			symListBottom->h.LinkName = m_strdup(h.LinkName);
-			if ((symListBottom->next = malloc(sizeof(symlinkList))) == NULL) {
-				free(symListBottom->h.LinkName);
-				free(symListBottom->h.Name);
-				status = -1;
-				errno = 0;
-				break;
-			}
+			symListBottom->next = m_malloc(sizeof(symlinkList));
+
 			symListBottom = symListBottom->next;
 			symListBottom->next = NULL;
 			status = 0;
@@ -225,12 +220,7 @@ TarExtractor(
                  if (*longp)
                    free(*longp);
 
-                 if (NULL == (*longp = (char *)malloc(h.Size))) {
-                   /* malloc failed, so bail */
-                   errno = 0;
-		   status = -1;
-		   break;
-                 }
+		*longp = m_malloc(h.Size);
                  bp = *longp;
 
                  // the way the GNU long{link,name} stuff works is like this:  

+ 1 - 1
src/archives.c

@@ -870,7 +870,7 @@ static int try_deconfigure_can(int (*force_p)(struct deppossi*),
       }
     }
     pkg->clientdata->istobe= itb_deconfigure;
-    newdeconf= malloc(sizeof(struct packageinlist));
+    newdeconf = m_malloc(sizeof(struct packageinlist));
     newdeconf->next= deconfigure;
     newdeconf->pkg= pkg;
     newdeconf->xinfo= removal;

+ 3 - 11
src/main.c

@@ -489,26 +489,18 @@ void execbackend(const char *const *argv) {
     pass_admindir = 1;
   }
 
-  nargv = malloc(sizeof(char *) * (argc + 2));
-  if (!nargv)
-    ohshite(_("couldn't malloc in execbackend"));
-
+  nargv = m_malloc(sizeof(char *) * (argc + 2));
   nargv[i] = m_strdup(cipaction->parg);
 
   i++, offset++;
 
   if (pass_admindir) {
-    nargv[i] = malloc((strlen("--admindir=") + strlen(admindir) + 1));
-    if (!nargv[i])
-      ohshite(_("couldn't malloc in execbackend"));
-
+    nargv[i] = m_malloc((strlen("--admindir=") + strlen(admindir) + 1));
     sprintf(nargv[i], "--admindir=%s", admindir);
     i++, offset++;
   }
 
-  nargv[i] = malloc(2 + strlen(cipaction->olong) + 1);
-  if (!nargv[i])
-    ohshite(_("couldn't malloc in execbackend"));
+  nargv[i] = m_malloc(2 + strlen(cipaction->olong) + 1);
   strcpy(nargv[i], "--");
   strcat(nargv[i], cipaction->olong);
   i++, offset++;