Changeset: fde83c143477 for MonetDB
URL: https://dev.monetdb.org/hg/MonetDB?cmd=changeset;node=fde83c143477
Modified Files:
        gdk/gdk_analytic_func.c
        sql/test/analytics/Tests/analytics04.sql
        sql/test/analytics/Tests/analytics04.stable.out
Branch: window-tunning
Log Message:

The input cannot be empty, otherwise there's an out of bounds access


diffs (truncated from 468 to 300 lines):

diff --git a/gdk/gdk_analytic_func.c b/gdk/gdk_analytic_func.c
--- a/gdk/gdk_analytic_func.c
+++ b/gdk/gdk_analytic_func.c
@@ -945,24 +945,27 @@ GDKanalytical##OP(BAT *r, BAT *p, BAT *o
        BATiter bpi = bat_iterator(b);                          \
        const void *nil = ATOMnilptr(tpe);                      \
        int (*atomcmp)(const void *, const void *) = ATOMcompare(tpe); \
-                                                                       \
-       switch (frame_type) {           \
-       case 3: /* unbounded until current row */       {       \
-               ANALYTICAL_MIN_MAX_BRANCHES(MIN_MAX, GT_LT, 
UNBOUNDED_TILL_CURRENT_ROW); \
-       } break;                \
-       case 4: /* current row until unbounded */       {       \
-               ANALYTICAL_MIN_MAX_BRANCHES(MIN_MAX, GT_LT, 
CURRENT_ROW_TILL_UNBOUNDED); \
-       } break;                \
-       case 5: /* all rows */  {       \
-               ANALYTICAL_MIN_MAX_BRANCHES(MIN_MAX, GT_LT, ALL_ROWS); \
-       } break;                \
-       case 6: /* current row */ {     \
-               ANALYTICAL_MIN_MAX_BRANCHES(MIN_MAX, GT_LT, CURRENT_ROW); \
-       } break;                \
-       default: {              \
-               ANALYTICAL_MIN_MAX_BRANCHES(MIN_MAX, GT_LT, OTHERS); \
-       }               \
-       }       \
+       \
+       if (cnt > 0) {  \
+               switch (frame_type) {           \
+               case 3: /* unbounded until current row */       {       \
+                       ANALYTICAL_MIN_MAX_BRANCHES(MIN_MAX, GT_LT, 
UNBOUNDED_TILL_CURRENT_ROW); \
+               } break;                \
+               case 4: /* current row until unbounded */       {       \
+                       ANALYTICAL_MIN_MAX_BRANCHES(MIN_MAX, GT_LT, 
CURRENT_ROW_TILL_UNBOUNDED); \
+               } break;                \
+               case 5: /* all rows */  {       \
+                       ANALYTICAL_MIN_MAX_BRANCHES(MIN_MAX, GT_LT, ALL_ROWS); \
+               } break;                \
+               case 6: /* current row */ {     \
+                       ANALYTICAL_MIN_MAX_BRANCHES(MIN_MAX, GT_LT, 
CURRENT_ROW); \
+               } break;                \
+               default: {              \
+                       ANALYTICAL_MIN_MAX_BRANCHES(MIN_MAX, GT_LT, OTHERS); \
+               }               \
+               }       \
+       } \
+       \
        BATsetcount(r, (BUN) cnt);                                              
\
        r->tnonil = !has_nils;                                          \
        r->tnil = has_nils;                                             \
@@ -1242,23 +1245,26 @@ GDKanalyticalcount(BAT *r, BAT *p, BAT *
        bool count_all = !ignore_nils || b->tnonil;
        BATiter bpi = bat_iterator(b);
 
-       switch (frame_type) {
-       case 3: /* unbounded until current row */       {
-               ANALYTICAL_COUNT_BRANCHES(UNBOUNDED_TILL_CURRENT_ROW);
-       } break;
-       case 4: /* current row until unbounded */       {
-               ANALYTICAL_COUNT_BRANCHES(CURRENT_ROW_TILL_UNBOUNDED);
-       } break;
-       case 5: /* all rows */  {
-               ANALYTICAL_COUNT_BRANCHES(ALL_ROWS);
-       } break;
-       case 6: /* current row */ {
-               ANALYTICAL_COUNT_BRANCHES(CURRENT_ROW);
-       } break;
-       default: {
-               ANALYTICAL_COUNT_BRANCHES(OTHERS);
+       if (cnt > 0) {
+               switch (frame_type) {
+               case 3: /* unbounded until current row */       {
+                       ANALYTICAL_COUNT_BRANCHES(UNBOUNDED_TILL_CURRENT_ROW);
+               } break;
+               case 4: /* current row until unbounded */       {
+                       ANALYTICAL_COUNT_BRANCHES(CURRENT_ROW_TILL_UNBOUNDED);
+               } break;
+               case 5: /* all rows */  {
+                       ANALYTICAL_COUNT_BRANCHES(ALL_ROWS);
+               } break;
+               case 6: /* current row */ {
+                       ANALYTICAL_COUNT_BRANCHES(CURRENT_ROW);
+               } break;
+               default: {
+                       ANALYTICAL_COUNT_BRANCHES(OTHERS);
+               }
+               }
        }
-       }
+
        BATsetcount(r, (BUN) cnt);
        r->tnonil = true;
        r->tnil = false;
@@ -1601,23 +1607,26 @@ GDKanalyticalsum(BAT *r, BAT *p, BAT *o,
        int abort_on_error = 1;
        BUN nils = 0;
 
-       switch (frame_type) {
-       case 3: /* unbounded until current row */       {
-               ANALYTICAL_SUM_BRANCHES(UNBOUNDED_TILL_CURRENT_ROW);
-       } break;
-       case 4: /* current row until unbounded */       {
-               ANALYTICAL_SUM_BRANCHES(CURRENT_ROW_TILL_UNBOUNDED);
-       } break;
-       case 5: /* all rows */  {
-               ANALYTICAL_SUM_BRANCHES(ALL_ROWS);
-       } break;
-       case 6: /* current row */ {
-               ANALYTICAL_SUM_BRANCHES(CURRENT_ROW);
-       } break;
-       default: {
-               ANALYTICAL_SUM_BRANCHES(OTHERS);
+       if (cnt > 0) {
+               switch (frame_type) {
+               case 3: /* unbounded until current row */       {
+                       ANALYTICAL_SUM_BRANCHES(UNBOUNDED_TILL_CURRENT_ROW);
+               } break;
+               case 4: /* current row until unbounded */       {
+                       ANALYTICAL_SUM_BRANCHES(CURRENT_ROW_TILL_UNBOUNDED);
+               } break;
+               case 5: /* all rows */  {
+                       ANALYTICAL_SUM_BRANCHES(ALL_ROWS);
+               } break;
+               case 6: /* current row */ {
+                       ANALYTICAL_SUM_BRANCHES(CURRENT_ROW);
+               } break;
+               default: {
+                       ANALYTICAL_SUM_BRANCHES(OTHERS);
+               }
+               }
        }
-       }
+
        BATsetcount(r, (BUN) cnt);
        r->tnonil = !has_nils;
        r->tnil = has_nils;
@@ -2058,22 +2067,24 @@ GDKanalyticalprod(BAT *r, BAT *p, BAT *o
        int abort_on_error = 1;
        BUN nils = 0;
 
-       switch (frame_type) {
-       case 3: /* unbounded until current row */       {
-               ANALYTICAL_PROD_BRANCHES(UNBOUNDED_TILL_CURRENT_ROW);
-       } break;
-       case 4: /* current row until unbounded */       {
-               ANALYTICAL_PROD_BRANCHES(CURRENT_ROW_TILL_UNBOUNDED);
-       } break;
-       case 5: /* all rows */  {
-               ANALYTICAL_PROD_BRANCHES(ALL_ROWS);
-       } break;
-       case 6: /* current row */ {
-               ANALYTICAL_PROD_BRANCHES(CURRENT_ROW);
-       } break;
-       default: {
-               ANALYTICAL_PROD_BRANCHES(OTHERS);
-       }
+       if (cnt > 0) {
+               switch (frame_type) {
+               case 3: /* unbounded until current row */       {
+                       ANALYTICAL_PROD_BRANCHES(UNBOUNDED_TILL_CURRENT_ROW);
+               } break;
+               case 4: /* current row until unbounded */       {
+                       ANALYTICAL_PROD_BRANCHES(CURRENT_ROW_TILL_UNBOUNDED);
+               } break;
+               case 5: /* all rows */  {
+                       ANALYTICAL_PROD_BRANCHES(ALL_ROWS);
+               } break;
+               case 6: /* current row */ {
+                       ANALYTICAL_PROD_BRANCHES(CURRENT_ROW);
+               } break;
+               default: {
+                       ANALYTICAL_PROD_BRANCHES(OTHERS);
+               }
+               }
        }
 
        BATsetcount(r, (BUN) cnt);
@@ -2396,22 +2407,24 @@ GDKanalyticalavg(BAT *r, BAT *p, BAT *o,
        lng sum = 0;
 #endif
 
-       switch (frame_type) {
-       case 3: /* unbounded until current row */       {
-               ANALYTICAL_AVG_BRANCHES(UNBOUNDED_TILL_CURRENT_ROW, LNG_HGE);
-       } break;
-       case 4: /* current row until unbounded */       {
-               ANALYTICAL_AVG_BRANCHES(CURRENT_ROW_TILL_UNBOUNDED, LNG_HGE);
-       } break;
-       case 5: /* all rows */  {
-               ANALYTICAL_AVG_BRANCHES(ALL_ROWS, LNG_HGE);
-       } break;
-       case 6: /* current row */ {
-               ANALYTICAL_AVG_BRANCHES(CURRENT_ROW, LNG_HGE);
-       } break;
-       default: {
-               ANALYTICAL_AVG_BRANCHES(OTHERS, LNG_HGE);
-       }
+       if (cnt > 0) {
+               switch (frame_type) {
+               case 3: /* unbounded until current row */       {
+                       ANALYTICAL_AVG_BRANCHES(UNBOUNDED_TILL_CURRENT_ROW, 
LNG_HGE);
+               } break;
+               case 4: /* current row until unbounded */       {
+                       ANALYTICAL_AVG_BRANCHES(CURRENT_ROW_TILL_UNBOUNDED, 
LNG_HGE);
+               } break;
+               case 5: /* all rows */  {
+                       ANALYTICAL_AVG_BRANCHES(ALL_ROWS, LNG_HGE);
+               } break;
+               case 6: /* current row */ {
+                       ANALYTICAL_AVG_BRANCHES(CURRENT_ROW, LNG_HGE);
+               } break;
+               default: {
+                       ANALYTICAL_AVG_BRANCHES(OTHERS, LNG_HGE);
+               }
+               }
        }
 
        BATsetcount(r, (BUN) cnt);
@@ -2600,22 +2613,24 @@ GDKanalyticalavginteger(BAT *r, BAT *p, 
        lng *restrict start = s ? (lng*)Tloc(s, 0) : NULL, *restrict end = e ? 
(lng*)Tloc(e, 0) : NULL;
        bit *np = p ? Tloc(p, 0) : NULL, *op = o ? Tloc(o, 0) : NULL;
 
-       switch (frame_type) {
-       case 3: /* unbounded until current row */       {
-               ANALYTICAL_AVG_INT_BRANCHES(UNBOUNDED_TILL_CURRENT_ROW);
-       } break;
-       case 4: /* current row until unbounded */       {
-               ANALYTICAL_AVG_INT_BRANCHES(CURRENT_ROW_TILL_UNBOUNDED);
-       } break;
-       case 5: /* all rows */  {
-               ANALYTICAL_AVG_INT_BRANCHES(ALL_ROWS);
-       } break;
-       case 6: /* current row */ {
-               ANALYTICAL_AVG_INT_BRANCHES(CURRENT_ROW);
-       } break;
-       default: {
-               ANALYTICAL_AVG_INT_BRANCHES(OTHERS);
-       }
+       if (cnt > 0) {
+               switch (frame_type) {
+               case 3: /* unbounded until current row */       {
+                       ANALYTICAL_AVG_INT_BRANCHES(UNBOUNDED_TILL_CURRENT_ROW);
+               } break;
+               case 4: /* current row until unbounded */       {
+                       ANALYTICAL_AVG_INT_BRANCHES(CURRENT_ROW_TILL_UNBOUNDED);
+               } break;
+               case 5: /* all rows */  {
+                       ANALYTICAL_AVG_INT_BRANCHES(ALL_ROWS);
+               } break;
+               case 6: /* current row */ {
+                       ANALYTICAL_AVG_INT_BRANCHES(CURRENT_ROW);
+               } break;
+               default: {
+                       ANALYTICAL_AVG_INT_BRANCHES(OTHERS);
+               }
+               }
        }
 
        BATsetcount(r, (BUN) cnt);
@@ -2813,22 +2828,24 @@ GDKanalytical_##NAME(BAT *r, BAT *p, BAT
        bit *np = p ? Tloc(p, 0) : NULL, *op = o ? Tloc(o, 0) : NULL;   \
        dbl *restrict rb = (dbl *) Tloc(r, 0), mean = 0, m2 = 0, delta; \
        \
-       switch (frame_type) {   \
-       case 3: /* unbounded until current row */       {       \
-               
ANALYTICAL_STATISTICS_BRANCHES(STDEV_VARIANCE_UNBOUNDED_TILL_CURRENT_ROW, 
SAMPLE, OP);  \
-       } break;        \
-       case 4: /* current row until unbounded */       {       \
-               
ANALYTICAL_STATISTICS_BRANCHES(STDEV_VARIANCE_CURRENT_ROW_TILL_UNBOUNDED, 
SAMPLE, OP);  \
-       } break;        \
-       case 5: /* all rows */  {       \
-               ANALYTICAL_STATISTICS_BRANCHES(STDEV_VARIANCE_ALL_ROWS, SAMPLE, 
OP);    \
-       } break;        \
-       case 6: /* current row */ {     \
-               ANALYTICAL_STATISTICS_BRANCHES(STDEV_VARIANCE_CURRENT_ROW, 
SAMPLE, OP); \
-       } break;        \
-       default: {      \
-               ANALYTICAL_STATISTICS_BRANCHES(STDEV_VARIANCE_OTHERS, SAMPLE, 
OP);      \
-       }       \
+       if (cnt > 0) {  \
+               switch (frame_type) {   \
+               case 3: /* unbounded until current row */       {       \
+                       
ANALYTICAL_STATISTICS_BRANCHES(STDEV_VARIANCE_UNBOUNDED_TILL_CURRENT_ROW, 
SAMPLE, OP);  \
+               } break;        \
+               case 4: /* current row until unbounded */       {       \
+                       
ANALYTICAL_STATISTICS_BRANCHES(STDEV_VARIANCE_CURRENT_ROW_TILL_UNBOUNDED, 
SAMPLE, OP);  \
+               } break;        \
+               case 5: /* all rows */  {       \
+                       ANALYTICAL_STATISTICS_BRANCHES(STDEV_VARIANCE_ALL_ROWS, 
SAMPLE, OP);    \
+               } break;        \
+               case 6: /* current row */ {     \
+                       
ANALYTICAL_STATISTICS_BRANCHES(STDEV_VARIANCE_CURRENT_ROW, SAMPLE, OP); \
+               } break;        \
+               default: {      \
+                       ANALYTICAL_STATISTICS_BRANCHES(STDEV_VARIANCE_OTHERS, 
SAMPLE, OP);      \
+               }       \
+               }       \
        }       \
        \
        BATsetcount(r, (BUN) cnt); \
@@ -2999,22 +3016,24 @@ GDKanalytical_##NAME(BAT *r, BAT *p, BAT
_______________________________________________
checkin-list mailing list
checkin-list@monetdb.org
https://www.monetdb.org/mailman/listinfo/checkin-list

Reply via email to