clang -fsanitize=undefined error in ecpg

From: Peter Eisentraut <peter_e(at)gmx(dot)net>
To: pgsql-hackers <pgsql-hackers(at)postgresql(dot)org>
Subject: clang -fsanitize=undefined error in ecpg
Date: 2015-03-31 19:09:26
Message-ID: 551AF0E6.4020900@gmx.net
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

With clang -fsanitize=undefined (clang-3.4), I get the following test failure in ecpg
(it's the only one in the entire tree):

--- a/src/interfaces/ecpg/test/expected/pgtypeslib-dt_test2.stderr
+++ b/src/interfaces/ecpg/test/results/pgtypeslib-dt_test2.stderr
@@ -1,2 +1,4 @@
[NO_PID]: ECPGdebug: set to 1
[NO_PID]: sqlca: code: 0, state: 00000
+dt_common.c:2209:13: runtime error: left shift of 1 by 31 places cannot be represented in type 'int'
+dt_common.c:1424:12: runtime error: left shift of 1 by 31 places cannot be represented in type 'int'

This happens while parsing these strings:

"19990108foobar"
"19990108 foobar",
"1999-01-08 foobar"
"........................Xaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"

(I'm not sure why it reports two warnings for four cases. Maybe it collapses some warnings.)

This patch fixes it:

diff --git a/src/interfaces/ecpg/pgtypeslib/dt.h b/src/interfaces/ecpg/pgtypeslib/dt.h
index 145e2b7..2ccd0be 100644
--- a/src/interfaces/ecpg/pgtypeslib/dt.h
+++ b/src/interfaces/ecpg/pgtypeslib/dt.h
@@ -193,7 +193,7 @@ typedef double fsec_t;
* Bit mask definitions for time parsing.
*/
/* Copy&pasted these values from src/include/utils/datetime.h */
-#define DTK_M(t) (0x01 << (t))
+#define DTK_M(t) ((t) == UNKNOWN_FIELD ? 0 : 0x01 << (t))
#define DTK_ALL_SECS_M (DTK_M(SECOND) | DTK_M(MILLISECOND) | DTK_M(MICROSECOND))
#define DTK_DATE_M (DTK_M(YEAR) | DTK_M(MONTH) | DTK_M(DAY))
#define DTK_TIME_M (DTK_M(HOUR) | DTK_M(MINUTE) | DTK_M(SECOND))

Strangely, I cannot reproduce this failure with the backend datetime code that
this was supposedly copied from.

Comments?

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Tom Lane 2015-03-31 19:09:34 Re: Exposing PG_VERSION_NUM in pg_config
Previous Message Tom Lane 2015-03-31 19:07:08 Re: GUC context information in the document.