* [PATCH tabled] server/server.c don't deref NULL on failed malloc
@ 2010-09-23 11:03 Jim Meyering
2010-09-23 14:07 ` Pete Zaitcev
0 siblings, 1 reply; 3+ messages in thread
From: Jim Meyering @ 2010-09-23 11:03 UTC (permalink / raw)
To: Project Hail
Signed-off-by: Jim Meyering <meyering@redhat.com>
---
Just noticed that sometimes tabled uses this idiom:
if (!(key = malloc(klen + 1)))
and sometimes this:
if ((key = malloc(klen + 1)) == NULL)
This time I used "... == NULL".
server/server.c | 3 ++-
1 files changed, 2 insertions(+), 1 deletions(-)
diff --git a/server/server.c b/server/server.c
index 2b4ef1c..3cec5ae 100644
--- a/server/server.c
+++ b/server/server.c
@@ -306,7 +306,8 @@ static char *pathtokey(const char *path)
return NULL;
klen = end - path;
- key = malloc(klen + 1);
+ if ((key = malloc(klen + 1)) == NULL)
+ return NULL;
memcpy(key, path, klen);
key[klen] = 0;
--
1.7.3.234.g7bba3
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH tabled] server/server.c don't deref NULL on failed malloc
2010-09-23 11:03 [PATCH tabled] server/server.c don't deref NULL on failed malloc Jim Meyering
@ 2010-09-23 14:07 ` Pete Zaitcev
2010-09-23 19:41 ` Jeff Garzik
0 siblings, 1 reply; 3+ messages in thread
From: Pete Zaitcev @ 2010-09-23 14:07 UTC (permalink / raw)
To: Jim Meyering; +Cc: Project Hail
On Thu, 23 Sep 2010 13:03:15 +0200
Jim Meyering <jim@meyering.net> wrote:
> Just noticed that sometimes tabled uses this idiom:
> if (!(key = malloc(klen + 1)))
> and sometimes this:
> if ((key = malloc(klen + 1)) == NULL)
> This time I used "... == NULL".
Er... The bang is Jeff's, which I try to follow always, but perhaps
one or two slipped due to opposing habit. IIRC pathtokey() was mine.
In fact tabled does not use assignments in conditions, dunno why
but it's a tradition.
-- Pete
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH tabled] server/server.c don't deref NULL on failed malloc
2010-09-23 14:07 ` Pete Zaitcev
@ 2010-09-23 19:41 ` Jeff Garzik
0 siblings, 0 replies; 3+ messages in thread
From: Jeff Garzik @ 2010-09-23 19:41 UTC (permalink / raw)
To: Pete Zaitcev; +Cc: Jim Meyering, Project Hail
On 09/23/2010 10:07 AM, Pete Zaitcev wrote:
> On Thu, 23 Sep 2010 13:03:15 +0200
> Jim Meyering<jim@meyering.net> wrote:
>
>> Just noticed that sometimes tabled uses this idiom:
>> if (!(key = malloc(klen + 1)))
>> and sometimes this:
>> if ((key = malloc(klen + 1)) == NULL)
>> This time I used "... == NULL".
>
> Er... The bang is Jeff's, which I try to follow always, but perhaps
> one or two slipped due to opposing habit. IIRC pathtokey() was mine.
> In fact tabled does not use assignments in conditions, dunno why
> but it's a tradition.
I always considered assignments in conditionals as fragile and
error-prone, and try to avoid them. However, I occasionally break my
own rule, such as with fgets(3) or getopt(3) loops.
And, getting back on topic, I do prefer implicit rather than explicit
testing for zero and non-zero... but that too is a "weak preference"
where I won't complain much if somebody else does it.
Typically the general rule for any codebase is "try to look like the
rest of the codebase."
Jeff
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2010-09-23 19:41 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2010-09-23 11:03 [PATCH tabled] server/server.c don't deref NULL on failed malloc Jim Meyering
2010-09-23 14:07 ` Pete Zaitcev
2010-09-23 19:41 ` Jeff Garzik
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.