summaryrefslogtreecommitdiff
path: root/source/luametatex/source/luarest
diff options
context:
space:
mode:
authorHans Hagen <pragma@wxs.nl>2023-01-04 12:09:26 +0100
committerContext Git Mirror Bot <phg@phi-gamma.net>2023-01-04 12:09:26 +0100
commit705b807c950a697d3c8be592c452a6fb3e561c7e (patch)
tree82904661aca945d008f07deb568ee7f05b55df4f /source/luametatex/source/luarest
parent62d980c99a617ff260f29ac2d3bdb084049f25b0 (diff)
downloadcontext-705b807c950a697d3c8be592c452a6fb3e561c7e.tar.gz
2023-01-04 11:35:00
Diffstat (limited to 'source/luametatex/source/luarest')
-rw-r--r--source/luametatex/source/luarest/lmtmd5lib.c2
-rw-r--r--source/luametatex/source/luarest/lmtoslibext.c27
-rw-r--r--source/luametatex/source/luarest/lmtstrlibext.c2
3 files changed, 14 insertions, 17 deletions
diff --git a/source/luametatex/source/luarest/lmtmd5lib.c b/source/luametatex/source/luarest/lmtmd5lib.c
index 2355b53ce..49730471a 100644
--- a/source/luametatex/source/luarest/lmtmd5lib.c
+++ b/source/luametatex/source/luarest/lmtmd5lib.c
@@ -64,7 +64,7 @@ static int md5lib_HEX(lua_State *L)
size_t size = 0; \
const char *data = lua_tolstring(L, 1, &size); \
md5_digest(data, size, (unsigned char *) result, CONVERSION); \
- lua_pushlstring(L, (const char *)result, RESULT_LENGTH); \
+ lua_pushlstring(L, (const char *) result, RESULT_LENGTH); \
return 1; \
} \
return 0; \
diff --git a/source/luametatex/source/luarest/lmtoslibext.c b/source/luametatex/source/luarest/lmtoslibext.c
index 74cbfad9e..0dc5fb940 100644
--- a/source/luametatex/source/luarest/lmtoslibext.c
+++ b/source/luametatex/source/luarest/lmtoslibext.c
@@ -113,15 +113,17 @@ static int oslib_sleep(lua_State *L)
DWORD sLength;
memset(uts, 0, sizeof(*uts));
osver.dwOSVersionInfoSize = sizeof(osver);
- GetVersionEx(&osver);
GetSystemInfo(&sysinfo);
strcpy(uts->sysname, "Windows");
+ /* When |GetVersionEx| becomes obsolete the version and release fields will be set to "". */
+ GetVersionEx(&osver);
sprintf(uts->version, "%ld.%02ld", osver.dwMajorVersion, osver.dwMinorVersion);
if (osver.szCSDVersion[0] != '\0' && (strlen(osver.szCSDVersion) + strlen(uts->version) + 1) < sizeof(uts->version)) {
strcat(uts->version, " ");
strcat(uts->version, osver.szCSDVersion);
}
sprintf(uts->release, "build %ld", osver.dwBuildNumber & 0xFFFF);
+ /* So far for the fragile and actually not that relevant part of |uts|. */
switch (sysinfo.wProcessorArchitecture) {
case PROCESSOR_ARCHITECTURE_AMD64:
strcpy(uts->machine, "x86_64");
@@ -281,14 +283,14 @@ static int oslib_execute(lua_State *L)
static int oslib_getenv(lua_State *L)
{
const char *key = luaL_checkstring(L, 1);
- char* val = NULL;
+ char *val = NULL;
if (key) {
size_t wlen = 0;
LPWSTR wkey = aux_utf8_to_wide(key);
_wgetenv_s(&wlen, NULL, 0, wkey);
if (wlen) {
LPWSTR wval = (LPWSTR) lmt_memory_malloc(wlen * sizeof(WCHAR));
- if (!_wgetenv_s(&wlen, wval, wlen, wkey)) {
+ if (! _wgetenv_s(&wlen, wval, wlen, wkey)) {
val = aux_utf8_from_wide(wval);
}
}
@@ -305,20 +307,15 @@ static int oslib_execute(lua_State *L)
{
const char *key = luaL_optstring(L, 1, NULL);
if (key) {
- LPWSTR wkey = aux_utf8_to_wide(key);
const char *val = luaL_optstring(L, 2, NULL);
- if (val) {
- LPWSTR wval = aux_utf8_to_wide(val);
- if (_wputenv_s(wkey, wval)) {
- return luaL_error(L, "unable to change environment");
- }
- lmt_memory_free(wval);
- } else {
- if (_wputenv_s(wkey, NULL)) {
- return luaL_error(L, "unable to change environment");
- }
- }
+ LPWSTR wkey = aux_utf8_to_wide(key);
+ LPWSTR wval = aux_utf8_to_wide(val ? val : "");
+ int bad = _wputenv_s(wkey, wval);
+ lmt_memory_free(wval);
lmt_memory_free(wkey);
+ if (bad) {
+ return luaL_error(L, "unable to change environment");
+ }
}
lua_pushboolean(L, 1);
return 1;
diff --git a/source/luametatex/source/luarest/lmtstrlibext.c b/source/luametatex/source/luarest/lmtstrlibext.c
index 5478c4b67..ffc687ff4 100644
--- a/source/luametatex/source/luarest/lmtstrlibext.c
+++ b/source/luametatex/source/luarest/lmtstrlibext.c
@@ -564,7 +564,7 @@ static int strlib_format_tounicode16(lua_State *L)
u = u - 0x10000; /* negative when invalid range */
u1 = (unsigned) (u >> 10) + 0xD800;
u2 = (unsigned) (u % 0x400) + 0xDC00;
- s[3] = strlib_aux_hexdigit((unsigned char) ((u1 & 0x000F) >> 0));
+ s[3] = strlib_aux_hexdigit((unsigned char) ((u1 & 0x000F) >> 0));
s[2] = strlib_aux_hexdigit((unsigned char) ((u1 & 0x00F0) >> 4));
s[1] = strlib_aux_hexdigit((unsigned char) ((u1 & 0x0F00) >> 8));
s[0] = strlib_aux_hexdigit((unsigned char) ((u1 & 0xF000) >> 12));