Changeset: 99ecdfb013e1 for MonetDB
URL: https://dev.monetdb.org/hg/MonetDB/rev/99ecdfb013e1
Modified Files:
        monetdb5/modules/atoms/str.c
        monetdb5/modules/kernel/batstr.c
Branch: Jun2023
Log Message:

fixed crash in asciify


diffs (54 lines):

diff --git a/monetdb5/modules/atoms/str.c b/monetdb5/modules/atoms/str.c
--- a/monetdb5/modules/atoms/str.c
+++ b/monetdb5/modules/atoms/str.c
@@ -5006,13 +5006,14 @@ STRasciify(str *r, const str *s)
                throw(MAL, "str.asciify", "ICONV: cannot convert from (%s) to 
(%s).", f, t);
        if ((*r = out = GDKmalloc(out_len)) == NULL)
                throw(MAL, "str.asciify", SQLSTATE(HY013) MAL_MALLOC_FAIL);
-       if (iconv(cd, &in, &in_len, &out, &out_len) == (size_t) - 1) {
+       str o = out;
+       if (iconv(cd, &in, &in_len, &o, &out_len) == (size_t) - 1) {
                GDKfree(out);
                *r = NULL;
                iconv_close(cd);
                throw(MAL, "str.asciify", "ICONV: string conversion failed from 
(%s) to (%s)", f, t);
        }
-       *out = '\0';
+       *o = '\0';
        iconv_close(cd);
        return MAL_SUCCEED;
 #else
diff --git a/monetdb5/modules/kernel/batstr.c b/monetdb5/modules/kernel/batstr.c
--- a/monetdb5/modules/kernel/batstr.c
+++ b/monetdb5/modules/kernel/batstr.c
@@ -5092,7 +5092,7 @@ BATSTRasciify(bat *ret, bat *bid)
                }
                in_len = strlen(in), out_len = in_len + 1;
                if (out == NULL) {
-                       if ((out = GDKmalloc(out_len)) == NULL) {
+                       if ((s = out = GDKmalloc(out_len)) == NULL) {
                                msg = createException(MAL,"batstr.asciify", 
MAL_MALLOC_FAIL);
                                goto exit;
                        }
@@ -5104,11 +5104,10 @@ BATSTRasciify(bat *ret, bat *bid)
                                goto exit;
                        }
                        prev_out_len = out_len;
+                       s = out;
                }
-               s = out;
+               out = s;
                if (iconv(cd, &in, &in_len, &out, &out_len) == (size_t) - 1) {
-                       GDKfree(out);
-                       s = NULL;
                        msg = createException(MAL,"batstr.asciify", "ICONV: 
string conversion failed");
                        goto exit;
                }
@@ -5119,6 +5118,7 @@ BATSTRasciify(bat *ret, bat *bid)
                }
        }
  exit:
+       GDKfree(s);
        bat_iterator_end(&bi);
        iconv_close(cd);
        finalize_output(ret, bn, msg, nils, q);
_______________________________________________
checkin-list mailing list -- [email protected]
To unsubscribe send an email to [email protected]

Reply via email to