From 37ebf16a37c19d18b9927cfa3e38c31992994fe4 Mon Sep 17 00:00:00 2001 From: Patrick Gundlach Date: Mon, 8 Dec 2025 21:04:12 +0100 Subject: [PATCH 1/2] Fix compiler warnings See #69 Building with CFLAGS="-std=gnu23 -Wall -Wextra -Wsign-compare" luarocks --local make gives no compiler warnings --- src/luaharfbuzz/buffer.c | 2 +- src/luaharfbuzz/face.c | 8 ++++---- src/luaharfbuzz/font.c | 8 ++++---- 3 files changed, 9 insertions(+), 9 deletions(-) diff --git a/src/luaharfbuzz/buffer.c b/src/luaharfbuzz/buffer.c index 5eb12eb..21e9bb2 100644 --- a/src/luaharfbuzz/buffer.c +++ b/src/luaharfbuzz/buffer.c @@ -143,7 +143,7 @@ static int buffer_add_codepoints(lua_State *L) { item_offset = luaL_optinteger(L, 3, 0); item_length = luaL_optinteger(L, 4, -1); - int n = lua_rawlen(L, 2); + unsigned int n = lua_rawlen(L, 2); hb_codepoint_t *text = (hb_codepoint_t *) malloc(n * sizeof(hb_codepoint_t)); diff --git a/src/luaharfbuzz/face.c b/src/luaharfbuzz/face.c index d6c4fe8..655da04 100644 --- a/src/luaharfbuzz/face.c +++ b/src/luaharfbuzz/face.c @@ -492,7 +492,7 @@ static int face_var_get_axis_infos(lua_State *L) { hb_ot_var_get_axis_infos(*face, start, &count, axis_infos); lua_createtable(L, count, 0); - for (int i = 0; i != count; i++) { + for (unsigned int i = 0; i != count; i++) { push_axis_info(L, axis_infos + i); lua_seti(L, -2, i + 1); } @@ -549,7 +549,7 @@ static int face_var_named_instance_get_design_coords(lua_State *L) { unsigned int count = STATIC_ARRAY_SIZE; count = hb_ot_var_named_instance_get_design_coords(*face, index, &count, coords); - for (int i = 0; i != count; i++) { + for (unsigned int i = 0; i != count; i++) { lua_pushnumber(L, coords[i]); } return count; @@ -570,7 +570,7 @@ static int face_var_normalize_variations(lua_State *L) { int normalized[STATIC_ARRAY_SIZE]; hb_ot_var_normalize_variations(*face, variations, count, normalized, coord_count); - for (int i = 0; i != coord_count; i++) { + for (unsigned int i = 0; i != coord_count; i++) { lua_pushinteger(L, normalized[i]); } return coord_count; @@ -590,7 +590,7 @@ static int face_var_normalize_coords(lua_State *L) { int normalized[STATIC_ARRAY_SIZE]; hb_ot_var_normalize_coords(*face, count, coords, normalized); - for (int i = 0; i != count; i++) { + for (unsigned int i = 0; i != count; i++) { lua_pushinteger(L, normalized[i]); } return count; diff --git a/src/luaharfbuzz/font.c b/src/luaharfbuzz/font.c index 4bb431d..f819cc4 100644 --- a/src/luaharfbuzz/font.c +++ b/src/luaharfbuzz/font.c @@ -249,7 +249,7 @@ static int font_set_variations(lua_State *L) { if (count > 128) count = 128; Variation variations[128]; - for (int i = 0; i != count; i++) + for (unsigned int i = 0; i != count; i++) variations[i] = *(Variation *)luaL_checkudata(L, i + 2, "harfbuzz.Variation"); hb_font_set_variations(*f, variations, count); @@ -262,7 +262,7 @@ static int font_set_var_coords_design(lua_State *L) { if (count > 128) count = 128; float coords[128]; - for (int i = 0; i != count; i++) + for (unsigned int i = 0; i != count; i++) coords[i] = luaL_checknumber(L, i + 2); hb_font_set_var_coords_design(*f, coords, count); @@ -275,7 +275,7 @@ static int font_set_var_coords_normalized(lua_State *L) { if (count > 128) count = 128; int coords[128]; - for (int i = 0; i != count; i++) + for (unsigned int i = 0; i != count; i++) coords[i] = luaL_checkinteger(L, i + 2); hb_font_set_var_coords_normalized(*f, coords, count); @@ -294,7 +294,7 @@ static int font_get_var_coords_normalized(lua_State *L) { Font *f = (Font *)luaL_checkudata(L, 1, "harfbuzz.Font"); unsigned int count; const int *coords = hb_font_get_var_coords_normalized(*f, &count); - for (int i = 0; i != count; i++) + for (unsigned int i = 0; i != count; i++) lua_pushinteger(L, coords[i]); return count; } From 02a3e62d766f3f46216a15e45aaff6e1b7f4e44a Mon Sep 17 00:00:00 2001 From: Patrick Gundlach Date: Mon, 8 Dec 2025 22:06:47 +0100 Subject: [PATCH 2/2] Add warning CFLAGS to Makefile --- Makefile | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/Makefile b/Makefile index 0984a8e..b4ff01c 100644 --- a/Makefile +++ b/Makefile @@ -1,7 +1,9 @@ DOCS_DIR := docs +# Default compiler flags (override with: make CFLAGS="..."). +CFLAGS ?= -Wall -Wextra -Wsign-compare -Werror build: - luarocks --local make + CFLAGS="$(CFLAGS)" luarocks --local make spec: test