* tiny patch: avoid an unnecessary test
@ 2007-03-16 8:28 Jim Meyering
2007-03-16 13:47 ` AJ Lewis
0 siblings, 1 reply; 3+ messages in thread
From: Jim Meyering @ 2007-03-16 8:28 UTC (permalink / raw)
To: dm-devel
Not a big deal (barely worth mentioning), but it might save
someone else a little time wondering "why".
2007-03-11 Jim Meyering <jim@meyering.net>
Remove unnecessary test.
* dmeventd/dmeventd.c (_alloc_dso_data): Don't test known-non-NULL
memset return value.
2007-03-11 Jim Meyering <jim@meyering.net>
Index: dmeventd/dmeventd.c
===================================================================
RCS file: /cvs/dm/device-mapper/dmeventd/dmeventd.c,v
retrieving revision 1.46
diff -u -p -r1.46 dmeventd.c
--- dmeventd/dmeventd.c 2 Feb 2007 17:08:51 -0000 1.46
+++ dmeventd/dmeventd.c 12 Mar 2007 14:39:35 -0000
@@ -258,8 +258,8 @@ static struct dso_data *_alloc_dso_data(
if (!ret)
return NULL;
- if (!memset(ret, 0, sizeof(*ret)) ||
- !(ret->dso_name = dm_strdup(data->dso_name))) {
+ memset(ret, 0, sizeof(*ret));
+ if (!(ret->dso_name = dm_strdup(data->dso_name))) {
dm_free(ret);
return NULL;
}
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: tiny patch: avoid an unnecessary test
2007-03-16 8:28 tiny patch: avoid an unnecessary test Jim Meyering
@ 2007-03-16 13:47 ` AJ Lewis
2007-03-16 14:25 ` AJ Lewis
0 siblings, 1 reply; 3+ messages in thread
From: AJ Lewis @ 2007-03-16 13:47 UTC (permalink / raw)
To: device-mapper development
[-- Attachment #1.1: Type: text/plain, Size: 1538 bytes --]
Actually, there's a chance you'd get a NULL pointer error if you don't have
that check if I'm reading the context right. Linux doesn't guarantee malloc
will return NULL if memory is unavailable, you only get the error when you
attempt to write to memory. So if there is an allocation error, you're only
going to see it in the memset.
--
AJ
On Fri, Mar 16, 2007 at 09:28:43AM +0100, Jim Meyering wrote:
> Not a big deal (barely worth mentioning), but it might save
> someone else a little time wondering "why".
>
> 2007-03-11 Jim Meyering <jim@meyering.net>
>
> Remove unnecessary test.
> * dmeventd/dmeventd.c (_alloc_dso_data): Don't test known-non-NULL
> memset return value.
>
> 2007-03-11 Jim Meyering <jim@meyering.net>
> Index: dmeventd/dmeventd.c
> ===================================================================
> RCS file: /cvs/dm/device-mapper/dmeventd/dmeventd.c,v
> retrieving revision 1.46
> diff -u -p -r1.46 dmeventd.c
> --- dmeventd/dmeventd.c 2 Feb 2007 17:08:51 -0000 1.46
> +++ dmeventd/dmeventd.c 12 Mar 2007 14:39:35 -0000
> @@ -258,8 +258,8 @@ static struct dso_data *_alloc_dso_data(
> if (!ret)
> return NULL;
>
> - if (!memset(ret, 0, sizeof(*ret)) ||
> - !(ret->dso_name = dm_strdup(data->dso_name))) {
> + memset(ret, 0, sizeof(*ret));
> + if (!(ret->dso_name = dm_strdup(data->dso_name))) {
> dm_free(ret);
> return NULL;
> }
>
> --
> dm-devel mailing list
> dm-devel@redhat.com
> https://www.redhat.com/mailman/listinfo/dm-devel
[-- Attachment #1.2: Type: application/pgp-signature, Size: 186 bytes --]
[-- Attachment #2: Type: text/plain, Size: 0 bytes --]
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: tiny patch: avoid an unnecessary test
2007-03-16 13:47 ` AJ Lewis
@ 2007-03-16 14:25 ` AJ Lewis
0 siblings, 0 replies; 3+ messages in thread
From: AJ Lewis @ 2007-03-16 14:25 UTC (permalink / raw)
To: device-mapper development
[-- Attachment #1.1: Type: text/plain, Size: 1892 bytes --]
Never mind - looking at the optimistic memory allocation stuff again, you'll
just get OOMed.
On Fri, Mar 16, 2007 at 08:47:02AM -0500, AJ Lewis wrote:
> Actually, there's a chance you'd get a NULL pointer error if you don't have
> that check if I'm reading the context right. Linux doesn't guarantee malloc
> will return NULL if memory is unavailable, you only get the error when you
> attempt to write to memory. So if there is an allocation error, you're only
> going to see it in the memset.
>
> --
> AJ
>
> On Fri, Mar 16, 2007 at 09:28:43AM +0100, Jim Meyering wrote:
> > Not a big deal (barely worth mentioning), but it might save
> > someone else a little time wondering "why".
> >
> > 2007-03-11 Jim Meyering <jim@meyering.net>
> >
> > Remove unnecessary test.
> > * dmeventd/dmeventd.c (_alloc_dso_data): Don't test known-non-NULL
> > memset return value.
> >
> > 2007-03-11 Jim Meyering <jim@meyering.net>
> > Index: dmeventd/dmeventd.c
> > ===================================================================
> > RCS file: /cvs/dm/device-mapper/dmeventd/dmeventd.c,v
> > retrieving revision 1.46
> > diff -u -p -r1.46 dmeventd.c
> > --- dmeventd/dmeventd.c 2 Feb 2007 17:08:51 -0000 1.46
> > +++ dmeventd/dmeventd.c 12 Mar 2007 14:39:35 -0000
> > @@ -258,8 +258,8 @@ static struct dso_data *_alloc_dso_data(
> > if (!ret)
> > return NULL;
> >
> > - if (!memset(ret, 0, sizeof(*ret)) ||
> > - !(ret->dso_name = dm_strdup(data->dso_name))) {
> > + memset(ret, 0, sizeof(*ret));
> > + if (!(ret->dso_name = dm_strdup(data->dso_name))) {
> > dm_free(ret);
> > return NULL;
> > }
> >
> > --
> > dm-devel mailing list
> > dm-devel@redhat.com
> > https://www.redhat.com/mailman/listinfo/dm-devel
> --
> dm-devel mailing list
> dm-devel@redhat.com
> https://www.redhat.com/mailman/listinfo/dm-devel
[-- Attachment #1.2: Type: application/pgp-signature, Size: 186 bytes --]
[-- Attachment #2: Type: text/plain, Size: 0 bytes --]
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2007-03-16 14:25 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2007-03-16 8:28 tiny patch: avoid an unnecessary test Jim Meyering
2007-03-16 13:47 ` AJ Lewis
2007-03-16 14:25 ` AJ Lewis
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.