Changeset: 8b4b2ef7df3f for MonetDB
URL: https://dev.monetdb.org/hg/MonetDB/rev/8b4b2ef7df3f
Modified Files:
        clients/mapiclient/mclient.c
Branch: default
Log Message:

Merge with Mar2025 branch.


diffs (208 lines):

diff --git a/clients/mapiclient/mclient.c b/clients/mapiclient/mclient.c
--- a/clients/mapiclient/mclient.c
+++ b/clients/mapiclient/mclient.c
@@ -375,9 +375,11 @@ utf8strlenmax(char *s, char *e, size_t m
        size_t len = 0, len0 = 0;
        char *t0 = s;
 
-       assert(max == 0 || t != NULL);
-       if (s == NULL)
+       if (s == NULL) {
+               if (t)
+                       *t = NULL;
                return 0;
+       }
 
        uint32_t state = 0, codepoint = 0;
        while (*s && (e == NULL || s < e)) {
@@ -385,7 +387,8 @@ utf8strlenmax(char *s, char *e, size_t m
                case UTF8_ACCEPT:
                        if (codepoint == '\n') {
                                if (max) {
-                                       *t = s - 1;     /* before the \n */
+                                       if (t)
+                                               *t = s - 1;     /* before the 
\n */
                                        return len;
                                }
                                len++;
@@ -401,15 +404,20 @@ utf8strlenmax(char *s, char *e, size_t m
                        }
                        if (max != 0) {
                                if (len > max) {
-                                       *t = t0;
+                                       if (t)
+                                               *t = t0;
                                        return len0;
                                }
                                if (len == max) {
-                                       /* add any following combining (zero 
width) characters */
-                                       do {
-                                               *t = s;
-                                               s = nextcharn(s, e == NULL ? 4 
: (size_t) (e - s), &codepoint);
-                                       } while (codepoint > 0 && 
charwidth(codepoint) == 0);
+                                       if (t) {
+                                               /* add any following combining 
(zero width)
+                                                * characters */
+                                               do {
+                                                       *t = s;
+                                                       s = nextcharn(s, e == 
NULL ? 4 : (size_t) (e - s),
+                                                                               
  &codepoint);
+                                               } while (codepoint > 0 && 
charwidth(codepoint) == 0);
+                                       }
                                        return len;
                                }
                        }
@@ -424,7 +432,7 @@ utf8strlenmax(char *s, char *e, size_t m
                        break;
                }
        }
-       if (max != 0)
+       if (t)
                *t = s;
        return len;
 }
@@ -461,7 +469,7 @@ SQLrow(int *len, int *numeric, char **re
        if (trim == 1) {
                for (i = 0; i < fields; i++) {
                        if ((t = rest[i]) != NULL &&
-                           utf8strlen(t, NULL) > (size_t) len[i]) {
+                               utf8strlenmax(t, NULL, (size_t) len[i] + 10, 
NULL) > (size_t) len[i]) {
                                /* eat leading whitespace */
                                while (*t != 0 && my_isspace(*t))
                                        t++;
@@ -481,7 +489,7 @@ SQLrow(int *len, int *numeric, char **re
                                             first ? '|' : i > 0 && cutafter[i 
- 1] == 0 ? '>' : ':',
                                             len[i], "");
                        } else {
-                               ulen = utf8strlen(rest[i], NULL);
+                               ulen = utf8strlenmax(rest[i], NULL, len[i], &t);
 
                                if (first && trim == 2) {
                                        /* calculate the height of
@@ -490,7 +498,7 @@ SQLrow(int *len, int *numeric, char **re
                                         * correction for a terminal
                                         * screen (1.62 * 2 -> 3 :
                                         * 9.72~10) */
-                                       if (ulen > (size_t) len[i]) {
+                                       if (ulen > (size_t) len[i] || *t) {
                                                cutafter[i] = 3 * len[i] / 10;
                                                if (cutafter[i] == 1)
                                                        cutafter[i]++;
@@ -503,11 +511,9 @@ SQLrow(int *len, int *numeric, char **re
 
                                /* break the string into pieces and
                                 * left-adjust them in the column */
-                               t = strchr(rest[i], '\n');
-                               if (ulen > (size_t) len[i] || t) {
+                               if (ulen > (size_t) len[i] || *t) {
                                        char *s;
 
-                                       t = utf8skip(rest[i], len[i]);
                                        if (trim == 1) {
                                                while (t > rest[i] && 
!my_isspace(*t))
                                                        while ((*--t & 0xC0) == 
0x80)
@@ -519,7 +525,7 @@ SQLrow(int *len, int *numeric, char **re
                                                     first ? '|' : i > 0 && 
cutafter[i - 1] == 0 ? '>' : ':');
                                        if (numeric[i])
                                                mnstr_printf(toConsole, "%*s",
-                                                            (int) (len[i] - 
(ulen - utf8strlen(t, NULL))),
+                                                            (int) (len[i] - 
ulen),
                                                             "");
 
                                        s = t;
@@ -529,7 +535,8 @@ SQLrow(int *len, int *numeric, char **re
                                        if (trim == 2 && *s == '\n')
                                                s++;
                                        if (*s && cutafter[i] == 0) {
-                                               t = utf8skip(rest[i], len[i] - 
2);
+                                               size_t x = 
utf8strlenmax(rest[i], NULL, len[i] - 2, &t);
+//                                             t = utf8skip(rest[i], len[i] - 
2);
                                                s = t;
                                                if (trim == 1)
                                                        while (my_isspace(*s))
@@ -559,7 +566,7 @@ SQLrow(int *len, int *numeric, char **re
                                                        }
                                                }
                                                mnstr_printf(toConsole, 
"...%*s",
-                                                            len[i] - 2 - (int) 
utf8strlen(rest[i], t),
+                                                            len[i] - 2 - (int) 
x,
                                                             "");
                                                croppedfields++;
                                        } else {
@@ -588,7 +595,7 @@ SQLrow(int *len, int *numeric, char **re
                                                mnstr_write(toConsole, " ", 1, 
1);
                                                if (!numeric[i])
                                                        mnstr_printf(toConsole, 
"%*s",
-                                                                    (int) 
(len[i] - (ulen - utf8strlen(t, NULL))),
+                                                                    (int) 
(len[i] - ulen),
                                                                     "");
                                        }
                                        rest[i] = *s ? s : 0;
@@ -1328,7 +1335,8 @@ sigint_handler(int signum)
 static void
 SQLrenderer(MapiHdl hdl)
 {
-       int i, total, lentotal, vartotal, minvartotal;
+       int i;
+       int64_t total, lentotal, vartotal, minvartotal;
        int fields, rfields, printfields = 0, max = 1, graphwaste = 0;
        int *len = NULL, *hdr = NULL, *numeric = NULL;
        char **rest = NULL;
diff --git a/clients/mapilib/mapi.c b/clients/mapilib/mapi.c
--- a/clients/mapilib/mapi.c
+++ b/clients/mapilib/mapi.c
@@ -2716,7 +2716,7 @@ read_line(Mapi mid)
 
                /* fetch one more block */
                if (mid->trace)
-                       printf("fetch next block: start at:%lu\n", (unsigned 
long) mid->blk.end);
+                       printf("fetch next block: start at:%zu\n", 
mid->blk.end);
                for (;;) {
                        len = mnstr_read(mid->from, mid->blk.buf + 
mid->blk.end, 1, BLOCK);
                        if (len == -1 && mnstr_errnr(mid->from) == 
MNSTR_INTERRUPT) {
@@ -3193,7 +3193,7 @@ parse_header_line(MapiHdl hdl, char *lin
                result->fieldcnt = n;
                for (i = 0; i < n; i++) {
                        if (anchors[i])
-                               result->fields[i].columnlength = 
atoi(anchors[i]);
+                               result->fields[i].columnlength = (int64_t) 
strtoll(anchors[i], NULL, 10);
                }
        } else if (strcmp(tag, "table_name") == 0) {
                result->fieldcnt = n;
@@ -4584,7 +4584,7 @@ mapi_get_len(MapiHdl hdl, int fnr)
 
        mapi_hdl_check0(hdl);
        if ((result = hdl->result) != 0 && fnr >= 0 && fnr < result->fieldcnt)
-               return result->fields[fnr].columnlength;
+               return result->fields[fnr].columnlength > INT_MAX ? INT_MAX : 
(int) result->fields[fnr].columnlength;
        mapi_setError(hdl->mid, "Illegal field number", __func__, MERROR);
        return 0;
 }
diff --git a/clients/mapilib/mapi_intern.h b/clients/mapilib/mapi_intern.h
--- a/clients/mapilib/mapi_intern.h
+++ b/clients/mapilib/mapi_intern.h
@@ -122,7 +122,7 @@ struct MapiColumn {
        char *tablename;
        char *columnname;
        char *columntype;
-       int columnlength;
+       int64_t columnlength;
        int digits;
        int scale;
 };
diff --git a/sql/test/BugTracker-2009/Tests/overflow.SF-2853458.test 
b/sql/test/BugTracker-2009/Tests/overflow.SF-2853458.test
--- a/sql/test/BugTracker-2009/Tests/overflow.SF-2853458.test
+++ b/sql/test/BugTracker-2009/Tests/overflow.SF-2853458.test
@@ -1,10 +1,12 @@
 skipif arch=aarch64
 skipif arch=ppc64le
+skipif arch=s390x
 statement error 22003!overflow in conversion of 9.2233720368547758e+18 to lng.
 select cast(power(2,63) as bigint)
 
 onlyif arch=aarch64
 onlyif arch=ppc64le
+onlyif arch=s390x
 query I
 select cast(power(2,63) as bigint)
 ----
_______________________________________________
checkin-list mailing list -- [email protected]
To unsubscribe send an email to [email protected]

Reply via email to