summaryrefslogtreecommitdiff
path: root/include
diff options
context:
space:
mode:
authorAndrew Opalach <andrew@akon.city> 2026-09-05 19:08:30 -0400
committerAndrew Opalach <andrew@akon.city> 2026-09-05 19:08:30 -0400
commitbc91d50afd91965fe740febdaee04719ae1b7996 (patch)
tree7c96d04699c6d7fdc5c1344de728dcb3ab742d4e /include
parentb617e3ccb25a0ac3c22f8c02722c8108b2f78d6e (diff)
downloadlibalabaster-bc91d50afd91965fe740febdaee04719ae1b7996.tar.gz
libalabaster-bc91d50afd91965fe740febdaee04719ae1b7996.tar.bz2
libalabaster-bc91d50afd91965fe740febdaee04719ae1b7996.zip
wstr: Minimal guarding against overflow
Still lots of potential overflows in wstr, the plan is to stop using wchar_t though. Signed-off-by: Andrew Opalach <andrew@akon.city>
Diffstat (limited to 'include')
-rw-r--r--include/al/wstr.h7
1 files changed, 3 insertions, 4 deletions
diff --git a/include/al/wstr.h b/include/al/wstr.h
index e5610a2..964d3d9 100644
--- a/include/al/wstr.h
+++ b/include/al/wstr.h
@@ -69,7 +69,7 @@ static inline void al_wstr_sized(wstr *w, u32 size)
static inline void al_wstr_clone(wstr *dest, wstr *src)
{
- u32 length = src->length;
+ size_t length = (size_t)src->length;
al_wstr_sized(dest, length + 1);
al_memcpy(dest->data, src->data, length * sizeof(wchar_t));
dest->data[length] = L'\0';
@@ -80,8 +80,7 @@ static inline bool al_wstr_from_cstr(wstr *w, char *c)
{
#ifdef AL_HAVE_WIDE_STRING
mbstate_t mbstate = { 0 };
- size_t length;
- length = mbsrtowcs(NULL, (const char **)&c, 0, &mbstate);
+ size_t length = mbsrtowcs(NULL, (const char **)&c, 0, &mbstate);
if (length == (size_t)-1) {
return false;
}
@@ -110,7 +109,7 @@ static inline bool al_str_from_wstr(str *s, wstr *w)
// This is broken on Windows. Locale issue?
#ifdef AL_HAVE_WIDE_STRING
wstr copy;
- // We have to make a copy here incase w->length is less than the
+ // We have to make a copy in case w->length is less than the
// full string pointed to by w->data.
al_wstr_clone(&copy, w);
wchar_t *copy_data = copy.data;