[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [pdf-devel] Doubt about pdf_alloc
From: |
jemarch |
Subject: |
Re: [pdf-devel] Doubt about pdf_alloc |
Date: |
Wed, 06 Jan 2010 11:01:17 +0100 |
User-agent: |
Wanderlust/2.14.0 (Africa) SEMI/1.14.6 (Maruoka) FLIM/1.14.8 (Shijō) APEL/10.6 Emacs/23.1.90 (i686-pc-linux-gnu) MULE/6.0 (HANACHIRUSATO) |
Hi Luca.
Sorry for the delay: I just returned from my winter holidays.
I'm looking at the code (pdf-alloc.c); a doubt about pdf_alloc
function. bzr code is
...
pointer = malloc (size);
if (!pointer && size != 0)
{
pointer = NULL;
}
...
Control flow enter the block if pointer is already NULL, isn't
it? If so the block seems (at least to me) to be useless. Is it
a placeholder for other things yet to come?
I applied a little patch that makes pdf_alloc to behave like glibc
malloc when 0 bytes are requested. See it below.
Thanks for reporting this :)
=== modified file 'ChangeLog'
--- ChangeLog 2009-12-22 18:05:56 +0000
+++ ChangeLog 2010-01-06 09:58:45 +0000
@@ -1,3 +1,12 @@
+2010-01-06 Jose E. Marchesi <address@hidden>
+
+ * doc/gnupdf.texi (Memory Allocation): Documentation for
+ `pdf_alloc' updated.
+
+ * src/base/pdf-alloc.c (pdf_alloc): Modified to use the same
+ semantics that glibc malloc when asked to allocate 0 bytes.
+ Reported by Luca Braglia.
+
2009-12-22 Jose E. Marchesi <address@hidden>
* src/base/pdf-types.c (pdf_i64_copy): Buggy assignment to
=== modified file 'doc/gnupdf.texi'
--- doc/gnupdf.texi 2009-12-18 13:15:59 +0000
+++ doc/gnupdf.texi 2010-01-06 09:55:50 +0000
@@ -320,7 +320,8 @@
@table @var
@item size
-The requested number of octects to allocate.
+The requested number of octects to allocate. If this value is
address@hidden then no memory is allocated and @code{NULL} is returned.
@end table
@item Returns
=== modified file 'src/base/pdf-alloc.c'
--- src/base/pdf-alloc.c 2009-09-02 14:48:25 +0000
+++ src/base/pdf-alloc.c 2010-01-06 09:56:54 +0000
@@ -1,4 +1,4 @@
-/* -*- mode: C -*- Time-stamp: "09/09/02 16:44:43 jemarch"
+/* -*- mode: C -*- Time-stamp: "10/01/06 10:56:54 jemarch"
*
* File: pdf-alloc.c
* Date: Fri Feb 22 21:05:05 2008
@@ -36,13 +36,13 @@
inline void *
pdf_alloc (const pdf_size_t size)
{
- void *pointer;
+ void *pointer = NULL;
- pointer = malloc (size);
- if (!pointer && size != 0)
+ if (size > 0)
{
- pointer = NULL;
+ pointer = malloc (size);
}
+
return pointer;
}
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- Re: [pdf-devel] Doubt about pdf_alloc,
jemarch <=