* [PATCH 1/3] column: use xalloc libs
@ 2011-12-20 13:36 Dave Reisner
2011-12-20 13:36 ` [PATCH 2/3] lscpu: " Dave Reisner
` (2 more replies)
0 siblings, 3 replies; 7+ messages in thread
From: Dave Reisner @ 2011-12-20 13:36 UTC (permalink / raw)
To: util-linux; +Cc: Dave Reisner
Signed-off-by: Dave Reisner <dreisner@archlinux.org>
---
text-utils/column.c | 2 +-
1 files changed, 1 insertions(+), 1 deletions(-)
diff --git a/text-utils/column.c b/text-utils/column.c
index 79d2842..c642680 100644
--- a/text-utils/column.c
+++ b/text-utils/column.c
@@ -395,7 +395,7 @@ static wchar_t *mbs_to_wcs(const char *s)
n = mbstowcs((wchar_t *)0, s, 0);
if (n < 0)
return NULL;
- wcs = malloc((n + 1) * sizeof(wchar_t));
+ wcs = xmalloc((n + 1) * sizeof(wchar_t));
if (!wcs)
return NULL;
n = mbstowcs(wcs, s, n + 1);
--
1.7.8
^ permalink raw reply related [flat|nested] 7+ messages in thread
* [PATCH 2/3] lscpu: use xalloc libs
2011-12-20 13:36 [PATCH 1/3] column: use xalloc libs Dave Reisner
@ 2011-12-20 13:36 ` Dave Reisner
2012-01-04 13:37 ` Karel Zak
2011-12-20 13:36 ` [PATCH 3/3] tools/checkxalloc.sh: add new code checking script Dave Reisner
2011-12-20 14:13 ` [PATCH 1/3] column: use xalloc libs Davidlohr Bueso
2 siblings, 1 reply; 7+ messages in thread
From: Dave Reisner @ 2011-12-20 13:36 UTC (permalink / raw)
To: util-linux; +Cc: Dave Reisner
Signed-off-by: Dave Reisner <dreisner@archlinux.org>
---
sys-utils/lscpu.c | 4 ++--
1 files changed, 2 insertions(+), 2 deletions(-)
diff --git a/sys-utils/lscpu.c b/sys-utils/lscpu.c
index 72b56d2..0a7841d 100644
--- a/sys-utils/lscpu.c
+++ b/sys-utils/lscpu.c
@@ -363,9 +363,9 @@ read_basicinfo(struct lscpu_desc *desc, struct lscpu_modifier *mod)
if (desc->flags) {
snprintf(buf, sizeof(buf), " %s ", desc->flags);
if (strstr(buf, " svm "))
- desc->virtflag = strdup("svm");
+ desc->virtflag = xstrdup("svm");
else if (strstr(buf, " vmx "))
- desc->virtflag = strdup("vmx");
+ desc->virtflag = xstrdup("vmx");
if (strstr(buf, " lm "))
desc->mode |= MODE_32BIT | MODE_64BIT; /* x86_64 */
if (strstr(buf, " zarch "))
--
1.7.8
^ permalink raw reply related [flat|nested] 7+ messages in thread
* [PATCH 3/3] tools/checkxalloc.sh: add new code checking script
2011-12-20 13:36 [PATCH 1/3] column: use xalloc libs Dave Reisner
2011-12-20 13:36 ` [PATCH 2/3] lscpu: " Dave Reisner
@ 2011-12-20 13:36 ` Dave Reisner
2012-01-04 13:39 ` Karel Zak
2011-12-20 14:13 ` [PATCH 1/3] column: use xalloc libs Davidlohr Bueso
2 siblings, 1 reply; 7+ messages in thread
From: Dave Reisner @ 2011-12-20 13:36 UTC (permalink / raw)
To: util-linux; +Cc: Dave Reisner
Finds usage of strdup, malloc, calloc, and realloc when xalloc.h is
included.
http://marc.info/?l=util-linux-ng&m=132438338929925&w=2
Signed-off-by: Dave Reisner <dreisner@archlinux.org>
---
Ask and you shall receive ;)
tools/checkxalloc.sh | 14 ++++++++++++++
1 files changed, 14 insertions(+), 0 deletions(-)
create mode 100755 tools/checkxalloc.sh
diff --git a/tools/checkxalloc.sh b/tools/checkxalloc.sh
new file mode 100755
index 0000000..f8f8c8c
--- /dev/null
+++ b/tools/checkxalloc.sh
@@ -0,0 +1,14 @@
+#!/bin/sh
+#
+# Find files which include the xalloc.h header, but which still call
+# the unwrapped calloc and malloc.
+#
+
+cd "$(git rev-parse --show-toplevel)" || {
+ echo "error: failed to chdir to git root"
+ exit 1
+}
+
+git grep -zl '#include "xalloc.h"' |
+ xargs -0 grep -nwE '[^x](([cm]|re)alloc|strdup)\('
+
--
1.7.8
^ permalink raw reply related [flat|nested] 7+ messages in thread
* Re: [PATCH 1/3] column: use xalloc libs
2011-12-20 13:36 [PATCH 1/3] column: use xalloc libs Dave Reisner
2011-12-20 13:36 ` [PATCH 2/3] lscpu: " Dave Reisner
2011-12-20 13:36 ` [PATCH 3/3] tools/checkxalloc.sh: add new code checking script Dave Reisner
@ 2011-12-20 14:13 ` Davidlohr Bueso
2012-01-04 13:37 ` Karel Zak
2 siblings, 1 reply; 7+ messages in thread
From: Davidlohr Bueso @ 2011-12-20 14:13 UTC (permalink / raw)
To: Dave Reisner; +Cc: util-linux, Dave Reisner
On Tue, 2011-12-20 at 08:36 -0500, Dave Reisner wrote:
> Signed-off-by: Dave Reisner <dreisner@archlinux.org>
> ---
> text-utils/column.c | 2 +-
> 1 files changed, 1 insertions(+), 1 deletions(-)
>
> diff --git a/text-utils/column.c b/text-utils/column.c
> index 79d2842..c642680 100644
> --- a/text-utils/column.c
> +++ b/text-utils/column.c
> @@ -395,7 +395,7 @@ static wchar_t *mbs_to_wcs(const char *s)
> n = mbstowcs((wchar_t *)0, s, 0);
> if (n < 0)
> return NULL;
> - wcs = malloc((n + 1) * sizeof(wchar_t));
> + wcs = xmalloc((n + 1) * sizeof(wchar_t));
> if (!wcs)
> return NULL;
Hmm this isn't that straight forward, if the memory allocation fails
here we don't necessarily abort the program.
> n = mbstowcs(wcs, s, n + 1);
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH 1/3] column: use xalloc libs
2011-12-20 14:13 ` [PATCH 1/3] column: use xalloc libs Davidlohr Bueso
@ 2012-01-04 13:37 ` Karel Zak
0 siblings, 0 replies; 7+ messages in thread
From: Karel Zak @ 2012-01-04 13:37 UTC (permalink / raw)
To: Davidlohr Bueso; +Cc: Dave Reisner, util-linux, Dave Reisner
On Tue, Dec 20, 2011 at 03:13:36PM +0100, Davidlohr Bueso wrote:
> On Tue, 2011-12-20 at 08:36 -0500, Dave Reisner wrote:
> > text-utils/column.c | 2 +-
> > 1 files changed, 1 insertions(+), 1 deletions(-)
Applied, thanks.
> > - wcs = malloc((n + 1) * sizeof(wchar_t));
> > + wcs = xmalloc((n + 1) * sizeof(wchar_t));
> > if (!wcs)
> > return NULL;
>
> Hmm this isn't that straight forward, if the memory allocation fails
> here we don't necessarily abort the program.
Fixed.
Karel
--
Karel Zak <kzak@redhat.com>
http://karelzak.blogspot.com
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH 2/3] lscpu: use xalloc libs
2011-12-20 13:36 ` [PATCH 2/3] lscpu: " Dave Reisner
@ 2012-01-04 13:37 ` Karel Zak
0 siblings, 0 replies; 7+ messages in thread
From: Karel Zak @ 2012-01-04 13:37 UTC (permalink / raw)
To: Dave Reisner; +Cc: util-linux, Dave Reisner
On Tue, Dec 20, 2011 at 08:36:03AM -0500, Dave Reisner wrote:
> sys-utils/lscpu.c | 4 ++--
> 1 files changed, 2 insertions(+), 2 deletions(-)
Applied, thanks.
--
Karel Zak <kzak@redhat.com>
http://karelzak.blogspot.com
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH 3/3] tools/checkxalloc.sh: add new code checking script
2011-12-20 13:36 ` [PATCH 3/3] tools/checkxalloc.sh: add new code checking script Dave Reisner
@ 2012-01-04 13:39 ` Karel Zak
0 siblings, 0 replies; 7+ messages in thread
From: Karel Zak @ 2012-01-04 13:39 UTC (permalink / raw)
To: Dave Reisner; +Cc: util-linux, Dave Reisner
On Tue, Dec 20, 2011 at 08:36:04AM -0500, Dave Reisner wrote:
> Ask and you shall receive ;)
Thanks :-)
> tools/checkxalloc.sh | 14 ++++++++++++++
> 1 files changed, 14 insertions(+), 0 deletions(-)
> create mode 100755 tools/checkxalloc.sh
>
> diff --git a/tools/checkxalloc.sh b/tools/checkxalloc.sh
> new file mode 100755
> index 0000000..f8f8c8c
> --- /dev/null
> +++ b/tools/checkxalloc.sh
> @@ -0,0 +1,14 @@
> +#!/bin/sh
> +#
> +# Find files which include the xalloc.h header, but which still call
> +# the unwrapped calloc and malloc.
> +#
> +
> +cd "$(git rev-parse --show-toplevel)" || {
> + echo "error: failed to chdir to git root"
> + exit 1
> +}
> +
> +git grep -zl '#include "xalloc.h"' |
> + xargs -0 grep -nwE '[^x](([cm]|re)alloc|strdup)\('
Applied, with small improvement -- we need a proper return value
(xargs returns too funny numbers) to make it usable from top-level
Makefile.
Karel
--
Karel Zak <kzak@redhat.com>
http://karelzak.blogspot.com
^ permalink raw reply [flat|nested] 7+ messages in thread
end of thread, other threads:[~2012-01-04 13:39 UTC | newest]
Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2011-12-20 13:36 [PATCH 1/3] column: use xalloc libs Dave Reisner
2011-12-20 13:36 ` [PATCH 2/3] lscpu: " Dave Reisner
2012-01-04 13:37 ` Karel Zak
2011-12-20 13:36 ` [PATCH 3/3] tools/checkxalloc.sh: add new code checking script Dave Reisner
2012-01-04 13:39 ` Karel Zak
2011-12-20 14:13 ` [PATCH 1/3] column: use xalloc libs Davidlohr Bueso
2012-01-04 13:37 ` Karel Zak
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.