Changeset: 8f1bc3d0fbf8 for MonetDB
URL: http://dev.monetdb.org/hg/MonetDB?cmd=changeset;node=8f1bc3d0fbf8
Modified Files:
        clients/odbc/driver/SQLGetFunctions.c
        gdk/gdk_aggr.c
        gdk/gdk_atoms.h
        gdk/gdk_unique.c
Branch: Jun2016
Log Message:

Avoid some undefined behavior according to the C standard.


diffs (141 lines):

diff --git a/clients/odbc/driver/SQLGetFunctions.c 
b/clients/odbc/driver/SQLGetFunctions.c
--- a/clients/odbc/driver/SQLGetFunctions.c
+++ b/clients/odbc/driver/SQLGetFunctions.c
@@ -399,7 +399,7 @@ SQLGetFunctions(SQLHDBC ConnectionHandle
                UWORD *p;
 
                for (p = FuncImplemented; p < 
&FuncImplemented[NFUNCIMPLEMENTED]; p++)
-                       FuncExistMap[*p >> 4] |= 1 << (*p & 0xF);
+                       FuncExistMap[*p >> 4] |= (UWORD) 1 << (*p & 0xF);
        }
 
        if (FunctionId == SQL_API_ODBC3_ALL_FUNCTIONS) {
diff --git a/gdk/gdk_aggr.c b/gdk/gdk_aggr.c
--- a/gdk/gdk_aggr.c
+++ b/gdk/gdk_aggr.c
@@ -237,8 +237,8 @@ BATgroupaggrinit(BAT *b, BAT *g, BAT *e,
                                                }                       \
                                        } else {                        \
                                                if (nil_if_empty &&     \
-                                                   !(seen[gid >> 5] & (1 << 
(gid & 0x1F)))) { \
-                                                       seen[gid >> 5] |= 1 << 
(gid & 0x1F); \
+                                                   !(seen[gid >> 5] & (1U << 
(gid & 0x1F)))) { \
+                                                       seen[gid >> 5] |= 1U << 
(gid & 0x1F); \
                                                        sums[gid] = 0;  \
                                                }                       \
                                                if (sums[gid] != TYPE2##_nil) { 
\
@@ -277,8 +277,8 @@ BATgroupaggrinit(BAT *b, BAT *g, BAT *e,
                                                }                       \
                                        } else {                        \
                                                if (nil_if_empty &&     \
-                                                   !(seen[gid >> 5] & (1 << 
(gid & 0x1F)))) { \
-                                                       seen[gid >> 5] |= 1 << 
(gid & 0x1F); \
+                                                   !(seen[gid >> 5] & (1U << 
(gid & 0x1F)))) { \
+                                                       seen[gid >> 5] |= 1U << 
(gid & 0x1F); \
                                                        sums[gid] = 0;  \
                                                }                       \
                                                if (sums[gid] != TYPE2##_nil) { 
\
@@ -704,8 +704,8 @@ BATsum(void *res, int tp, BAT *b, BAT *s
                                        }                               \
                                } else {                                \
                                        if (nil_if_empty &&             \
-                                           !(seen[gid >> 5] & (1 << (gid & 
0x1F)))) { \
-                                               seen[gid >> 5] |= 1 << (gid & 
0x1F); \
+                                           !(seen[gid >> 5] & (1U << (gid & 
0x1F)))) { \
+                                               seen[gid >> 5] |= 1U << (gid & 
0x1F); \
                                                prods[gid] = 1;         \
                                        }                               \
                                        if (prods[gid] != TYPE2##_nil) { \
@@ -749,8 +749,8 @@ BATsum(void *res, int tp, BAT *b, BAT *s
                                                gid = (oid) i;          \
                                }                                       \
                                if (nil_if_empty &&                     \
-                                   !(seen[gid >> 5] & (1 << (gid & 0x1F)))) { \
-                                       seen[gid >> 5] |= 1 << (gid & 0x1F); \
+                                   !(seen[gid >> 5] & (1U << (gid & 0x1F)))) { 
\
+                                       seen[gid >> 5] |= 1U << (gid & 0x1F); \
                                        prods[gid] = 1;                 \
                                }                                       \
                                if (vals[i] == TYPE##_nil) {            \
@@ -801,8 +801,8 @@ BATsum(void *res, int tp, BAT *b, BAT *s
                                        }                               \
                                } else {                                \
                                        if (nil_if_empty &&             \
-                                           !(seen[gid >> 5] & (1 << (gid & 
0x1F)))) { \
-                                               seen[gid >> 5] |= 1 << (gid & 
0x1F); \
+                                           !(seen[gid >> 5] & (1U << (gid & 
0x1F)))) { \
+                                               seen[gid >> 5] |= 1U << (gid & 
0x1F); \
                                                prods[gid] = 1;         \
                                        }                               \
                                        if (prods[gid] != lng_nil) {    \
@@ -851,8 +851,8 @@ BATsum(void *res, int tp, BAT *b, BAT *s
                                        }                               \
                                } else {                                \
                                        if (nil_if_empty && \
-                                           !(seen[gid >> 5] & (1 << (gid & 
0x1F)))) { \
-                                               seen[gid >> 5] |= 1 << (gid & 
0x1F); \
+                                           !(seen[gid >> 5] & (1U << (gid & 
0x1F)))) { \
+                                               seen[gid >> 5] |= 1U << (gid & 
0x1F); \
                                                prods[gid] = 1;         \
                                        }                               \
                                        if (prods[gid] != TYPE2##_nil) { \
diff --git a/gdk/gdk_atoms.h b/gdk/gdk_atoms.h
--- a/gdk/gdk_atoms.h
+++ b/gdk/gdk_atoms.h
@@ -126,7 +126,7 @@ gdk_export int escapedStr(char *dst, con
 #ifdef HAVE_HGE
 #define GDK_hge_max ((((hge) 1) << 126) - 1 + \
                      (((hge) 1) << 126))
-#define GDK_hge_min (((hge) 1) << 127)
+#define GDK_hge_min (-GDK_hge_max-1)
 #endif
 #define GDK_dbl_max ((dbl) DBL_MAX)
 #define GDK_dbl_min (-GDK_dbl_max)
diff --git a/gdk/gdk_unique.c b/gdk/gdk_unique.c
--- a/gdk/gdk_unique.c
+++ b/gdk/gdk_unique.c
@@ -193,8 +193,8 @@ BATunique(BAT *b, BAT *s)
                                        break;
                        }
                        val = ((const unsigned char *) vals)[i];
-                       if (!(seen[val >> 4] & (1 << (val & 0xF)))) {
-                               seen[val >> 4] |= 1 << (val & 0xF);
+                       if (!(seen[val >> 4] & (1U << (val & 0xF)))) {
+                               seen[val >> 4] |= 1U << (val & 0xF);
                                o = i + b->hseqbase;
                                bunfastapp(bn, &o);
                                if (bn->batCount == 256) {
@@ -230,8 +230,8 @@ BATunique(BAT *b, BAT *s)
                                        break;
                        }
                        val = ((const unsigned short *) vals)[i];
-                       if (!(seen[val >> 4] & (1 << (val & 0xF)))) {
-                               seen[val >> 4] |= 1 << (val & 0xF);
+                       if (!(seen[val >> 4] & (1U << (val & 0xF)))) {
+                               seen[val >> 4] |= 1U << (val & 0xF);
                                o = i + b->hseqbase;
                                bunfastapp(bn, &o);
                                if (bn->batCount == 65536) {
@@ -320,18 +320,18 @@ BATunique(BAT *b, BAT *s)
                nme = BBP_physical(b->batCacheid);
                nmelen = strlen(nme);
                if (ATOMbasetype(b->ttype) == TYPE_bte) {
-                       mask = 1 << 8;
+                       mask = (BUN) 1 << 8;
                        cmp = NULL; /* no compare needed, "hash" is perfect */
                } else if (ATOMbasetype(b->ttype) == TYPE_sht) {
-                       mask = 1 << 16;
+                       mask = (BUN) 1 << 16;
                        cmp = NULL; /* no compare needed, "hash" is perfect */
                } else {
                        if (s)
                                mask = HASHmask(s->batCount);
                        else
                                mask = HASHmask(b->batCount);
-                       if (mask < (1 << 16))
-                               mask = 1 << 16;
+                       if (mask < ((BUN) 1 << 16))
+                               mask = (BUN) 1 << 16;
                }
                if ((hp = GDKzalloc(sizeof(Heap))) == NULL ||
                    (hp->filename = GDKmalloc(nmelen + 30)) == NULL ||
_______________________________________________
checkin-list mailing list
checkin-list@monetdb.org
https://www.monetdb.org/mailman/listinfo/checkin-list

Reply via email to