cproc

Unnamed repository; edit this file 'description' to name the repository.
git clone git://git.nihaljere.xyz/cproc
Log | Files | Refs | Submodules | README | LICENSE

commit 73725d271ea81357e91cebdbd08602a2c3d86933
parent bca4edbf1b1112f36ba7093cdd15730e8eea253c
Author: Nihal Jere <nihal@nihaljere.xyz>
Date:   Fri, 26 Mar 2021 21:14:50 -0500

temp

Diffstat:
Mexpr.c | 29++++++++++++++---------------
1 file changed, 14 insertions(+), 15 deletions(-)

diff --git a/expr.c b/expr.c @@ -13,7 +13,7 @@ #include "cc.h" static size_t -mbstoc16s(char16_t *dest, const char *src, size_t n) +mbstoc16(char16_t *dest, const char *src, size_t n) { size_t ret, w = 0; do { @@ -28,12 +28,12 @@ mbstoc16s(char16_t *dest, const char *src, size_t n) return -1; } } while (ret != 0 && n > 0); - + return w; } static size_t -mbstoc32s(char32_t *dest, const char *src, size_t n) +mbstoc32(char32_t *dest, const char *src, size_t n) { size_t ret, w = 0; do { @@ -525,19 +525,19 @@ primaryexpr(struct scope *s) case 'L': ++src; t = targ->typewchar; np = 'w'; goto litknown; case 'U': ++src; t = &typeushort; np = 'U'; goto litknown; case '"': t = &typechar; np = 'c'; goto litknown; - case 'u': ++src; break; + case 'u': ++src; } switch (*src) { default: error(&tok.loc, "invalid prefix for string literal"); case '"': t = &typeushort; np = 'u'; break; - case '8': ++src; t = &typechar; np = '8'; break; + case '8': ++src; t = &typechar; np = '8'; } +litknown: if (p && p != np && !(p == 'c' || np == 'c')) error(&tok.loc, "cannot have adjacent string literals with different prefixes"); -litknown: p = np; tmp = xreallocarray(tmp, tmpsize + strlen(tok.lit), 1); - /* mbsto* will calculate length incorrectly if this isn't cleared */ + /* mbstowcs might miscalculate length without this */ memset(tmp + tmpsize, 0, strlen(tok.lit)); dst = tmp + tmpsize; for (++src; *src != '"'; ++dst) @@ -548,20 +548,19 @@ litknown: e = mkexpr(EXPRSTRING, mkarraytype(t, QUALNONE, 0)); e->lvalue = true; e->string.data = NULL; - e->string.size = tmpsize; switch (p) { case 'c': case '8': e->string.size = tmpsize; e->string.data = tmp; goto litdone; - case 'w': e->string.size = mbstowcs(NULL, tmp, tmpsize) + 1; break; - case 'u': e->string.size = mbstoc16s(NULL, tmp, tmpsize) + 1; break; - case 'U': e->string.size = mbstoc32s(NULL, tmp, tmpsize) + 1; break; + case 'w': e->string.size = mbstowcs(NULL, tmp, 0) + 1; break; + case 'u': e->string.size = mbstoc16(NULL, tmp, tmpsize) + 1; break; + case 'U': e->string.size = mbstoc32(NULL, tmp, tmpsize) + 1; break; default: assert(0); } e->string.data = xreallocarray(e->string.data, e->string.size, t->size); switch (p) { - case 'w': count = mbstowcs(e->string.data, tmp, e->string.size); break; - case 'u': count = mbstoc16s(e->string.data, tmp, e->string.size); break; - case 'U': count = mbstoc32s(e->string.data, tmp, e->string.size); break; + case 'w': count = mbstowcs((wchar_t *)e->string.data, tmp, e->string.size); break; + case 'u': count = mbstoc16((char16_t *)e->string.data, tmp, tmpsize); break; + case 'U': count = mbstoc32((char32_t *)e->string.data, tmp, tmpsize); break; default: assert(0); } if (count == -1) @@ -569,7 +568,7 @@ litknown: assert(count == e->string.size - 1); free(tmp); litdone: - e->type->array.length = e->string.size + 1; + e->type->array.length = e->string.size - 1; e->type->size = e->type->array.length * e->type->base->size; e->type->incomplete = false; e = decay(e);