Re: [PATCH] gcc warning 'expression which evaluates to zero treated as a null pointer'

2019-11-14 Thread didier
Hi,

On Wed, Nov 13, 2019 at 10:01 PM Tom Lane  wrote:
>
> didier  writes:
> > clang -E output before 7a0574b5
> > HeapTuple newtuple = 0;
> > with 7a0574b5
> > HeapTuple newtuple = ((bool) 0);
>
> Hm, did you re-run configure after 7a0574b5?  If you didn't, it would
> have gone through the not-stdbool.h path in c.h, which might account
> for this.  It's a good catch though, even if by accident :-)
Yes, that's it. I should have known better, it's no the first time I
made this mistake,
thanks.

Didier




Re: [PATCH] gcc warning 'expression which evaluates to zero treated as a null pointer'

2019-11-13 Thread Tom Lane
didier  writes:
> clang -E output before 7a0574b5
> HeapTuple newtuple = 0;
> with 7a0574b5
> HeapTuple newtuple = ((bool) 0);

Hm, did you re-run configure after 7a0574b5?  If you didn't, it would
have gone through the not-stdbool.h path in c.h, which might account
for this.  It's a good catch though, even if by accident :-)

regards, tom lane




Re: [PATCH] gcc warning 'expression which evaluates to zero treated as a null pointer'

2019-11-13 Thread didier
Hi,
On Wed, Nov 13, 2019 at 8:52 PM Tom Lane  wrote:
>
> didier  writes:
> > Trivial patch:
> > - remove a gcc warning (since commit 7a0574b5)
> > expression which evaluates to zero treated as a null pointer constant of
> >   type 'HeapTuple' (aka 'struct HeapTupleData *')
>
> Hmm, the initializations "HeapTuple newtuple = false" are certainly
> bogus-looking and not per project style; I wonder who's to blame for
> those?  (I do not see what 7a0574b5 would have had to do with it;
> that didn't affect any backend code.)

My mistake it's not gcc but clang for JIT, maybe because it could
change false definition?
clang version: 6.0.0-1ubuntu2
clang -E output before 7a0574b5
HeapTuple newtuple = 0;
with 7a0574b5
HeapTuple newtuple = ((bool) 0);

>
> > - always use "if (newtuple == NULL)" rather than mixing !newtuple and
> > newtuple == NULL
>
> Don't particularly agree with these changes though.  "if (!ptr)" is
> a very common C idiom, and no programmer would tolerate a compiler
> that warned about it.
There's no warning, it's stylistic. In the same function there's both
forms a couple of lines apart: "if (!ptr)" follow by "if (ptr ==
NULL)", using only one form is smother on the brain, at least mine.

Regards
Didier




Re: [PATCH] gcc warning 'expression which evaluates to zero treated as a null pointer'

2019-11-13 Thread Tom Lane
didier  writes:
> Trivial patch:
> - remove a gcc warning (since commit 7a0574b5)
> expression which evaluates to zero treated as a null pointer constant of
>   type 'HeapTuple' (aka 'struct HeapTupleData *')

Hmm, the initializations "HeapTuple newtuple = false" are certainly
bogus-looking and not per project style; I wonder who's to blame for
those?  (I do not see what 7a0574b5 would have had to do with it;
that didn't affect any backend code.)

> - always use "if (newtuple == NULL)" rather than mixing !newtuple and
> newtuple == NULL

Don't particularly agree with these changes though.  "if (!ptr)" is
a very common C idiom, and no programmer would tolerate a compiler
that warned about it.

regards, tom lane




[PATCH] gcc warning 'expression which evaluates to zero treated as a null pointer'

2019-11-13 Thread didier
Hi,
Trivial patch:
- remove a gcc warning (since commit 7a0574b5)
expression which evaluates to zero treated as a null pointer constant of
  type 'HeapTuple' (aka 'struct HeapTupleData *')

- always use "if (newtuple == NULL)" rather than mixing !newtuple and
newtuple == NULL

Regards
Didier
diff --git a/src/backend/commands/trigger.c b/src/backend/commands/trigger.c
index 84144b46b1..0467a4811b 100644
--- a/src/backend/commands/trigger.c
+++ b/src/backend/commands/trigger.c
@@ -2533,7 +2533,7 @@ ExecBRInsertTriggers(EState *estate, ResultRelInfo *relinfo,
 	 TupleTableSlot *slot)
 {
 	TriggerDesc *trigdesc = relinfo->ri_TrigDesc;
-	HeapTuple	newtuple = false;
+	HeapTuple	newtuple = NULL;
 	bool		should_free;
 	TriggerData LocTriggerData;
 	int			i;
@@ -2563,7 +2563,7 @@ ExecBRInsertTriggers(EState *estate, ResultRelInfo *relinfo,
 			NULL, NULL, slot))
 			continue;
 
-		if (!newtuple)
+		if (newtuple == NULL)
 			newtuple = ExecFetchSlotHeapTuple(slot, true, _free);
 
 		LocTriggerData.tg_trigslot = slot;
@@ -3178,7 +3178,7 @@ ExecIRUpdateTriggers(EState *estate, ResultRelInfo *relinfo,
 {
 	TriggerDesc *trigdesc = relinfo->ri_TrigDesc;
 	TupleTableSlot *oldslot = ExecGetTriggerOldSlot(estate, relinfo);
-	HeapTuple	newtuple = false;
+	HeapTuple	newtuple = NULL;
 	bool		should_free;
 	TriggerData LocTriggerData;
 	int			i;
@@ -3207,7 +3207,7 @@ ExecIRUpdateTriggers(EState *estate, ResultRelInfo *relinfo,
 			NULL, oldslot, newslot))
 			continue;
 
-		if (!newtuple)
+		if (newtuple == NULL)
 			newtuple = ExecFetchSlotHeapTuple(newslot, true, _free);
 
 		LocTriggerData.tg_trigslot = oldslot;