From f46dc87b36c20f02134afb2297a9e093065f7af8 Mon Sep 17 00:00:00 2001 From: mitchell <70453897+667e-11@users.noreply.github.com> Date: Wed, 29 Oct 2014 14:55:04 -0400 Subject: Fixed compiler warnings. --- src/Makefile | 26 ++++++++++++-------------- src/textadept.c | 39 ++++++++++++++++++++++----------------- 2 files changed, 34 insertions(+), 31 deletions(-) (limited to 'src') diff --git a/src/Makefile b/src/Makefile index 5124447d..4d8a5ca6 100644 --- a/src/Makefile +++ b/src/Makefile @@ -5,8 +5,8 @@ CXX = g++ ifeq (win, $(findstring win, $(MAKECMDGOALS))) # Cross-compile for Win32. CROSS = i686-w64-mingw32- - CFLAGS = -mms-bitfields - CXXFLAGS = -mms-bitfields -static-libgcc -static-libstdc++ + CFLAGS = -mms-bitfields -Os + CXXFLAGS = -mms-bitfields -static-libgcc -static-libstdc++ -Os LUA_CFLAGS = -DLUA_BUILD_AS_DLL -DLUA_LIB LDFLAGS = -Wl,--retain-symbols-file -Wl,lua.sym ifeq (, $(findstring curses, $(MAKECMDGOALS))) @@ -36,9 +36,9 @@ else ifeq (osx, $(findstring osx, $(MAKECMDGOALS))) # Cross-compile for Mac OSX. CROSS = i686-apple-darwin10- CFLAGS = -m32 -arch i386 -mdynamic-no-pic -mmacosx-version-min=10.5 \ - -isysroot /usr/lib/apple/SDKs/MacOSX10.5.sdk + -isysroot /usr/lib/apple/SDKs/MacOSX10.5.sdk -Os CXXFLAGS = -m32 -arch i386 -mdynamic-no-pic -mmacosx-version-min=10.5 \ - -isysroot /usr/lib/apple/SDKs/MacOSX10.5.sdk + -isysroot /usr/lib/apple/SDKs/MacOSX10.5.sdk -Os LUA_CFLAGS = -DLUA_USE_MACOSX LDFLAGS = -liconv -rdynamic MAKE = make @@ -61,6 +61,8 @@ else ifeq (osx, $(findstring osx, $(MAKECMDGOALS))) libluajit = luajit/src/libluajit.osx.a else # Build for Linux/BSD. + CFLAGS = -Os + CXXFLAGS = -Os LUA_CFLAGS = -DLUA_USE_LINUX LDFLAGS = -rdynamic -Wl,--retain-symbols-file -Wl,lua.sym ifeq (Linux, $(shell uname -s)) @@ -96,9 +98,8 @@ endif # Scintilla. -sci_flags = -pedantic -Os $(plat_flag) -DSCI_LEXER -DNDEBUG \ - -DG_THREADS_IMPL_NONE -Iscintilla/include -Iscintilla/src \ - -Iscintilla/lexlib -Wall -Wno-char-subscripts +sci_flags = -pedantic $(plat_flag) -DSCI_LEXER -DNDEBUG -DG_THREADS_IMPL_NONE \ + -Iscintilla/include -Iscintilla/src -Iscintilla/lexlib -Wall sci_objs = AutoComplete.o CallTip.o CaseConvert.o CaseFolder.o Catalogue.o \ CellBuffer.o CharClassify.o ContractionState.o Decoration.o \ @@ -114,9 +115,8 @@ lexlpeg_objs = LexLPeg.o LexLPegjit.o LexLPeg-curses.o LexLPegjit-curses.o # Textadept. -ta_flags = -std=c99 -Os -D_POSIX_C_SOURCE=200809L -D_DARWIN_C_SOURCE \ - $(plat_flag) -Iscintilla/include -Igtdialog -W -Wall \ - -Wno-sign-compare -Wno-unused +ta_flags = -std=c99 -D_POSIX_C_SOURCE=200809L -D_DARWIN_C_SOURCE $(plat_flag) \ + -Iscintilla/include -Igtdialog -W -Wall -Wno-unused textadept_gtk_objs = textadept.o textadeptjit.o textadept_curses_objs = textadept-curses.o textadeptjit-curses.o @@ -142,10 +142,8 @@ cdk_objs = binding.o buttonbox.o button.o cdk.o cdk_display.o cdk_objs.o \ # Add debugging symbols and disable optimizations when DEBUG=1. ifdef DEBUG - CFLAGS += -g - CXXFLAGS += -g - sci_flags += -O0 - ta_flags += -O0 + CFLAGS += -g -O0 + CXXFLAGS += -g -O0 endif # Build. diff --git a/src/textadept.c b/src/textadept.c index fb47bf3c..06c9969c 100644 --- a/src/textadept.c +++ b/src/textadept.c @@ -701,13 +701,13 @@ static int lui_goto_view(lua_State *L) { if (relative) { l_pushview(L, focused_view), lua_gettable(L, -2); n = lua_tointeger(L, -1) + n; - if (n > lua_rawlen(L, -2)) + if (n > (int)lua_rawlen(L, -2)) n = 1; else if (n < 1) n = lua_rawlen(L, -2); lua_rawgeti(L, -2, n); } else { - luaL_argcheck(L, n > 0 && n <= lua_rawlen(L, -1), 1, + luaL_argcheck(L, n > 0 && n <= (int)lua_rawlen(L, -1), 1, "no View exists at that index"); lua_rawgeti(L, -1, n); } @@ -759,7 +759,7 @@ static void l_pushmenu(lua_State *L, int index, GCallback callback, gtk_menu_item_set_submenu(GTK_MENU_ITEM(submenu_root), menu); } lua_pop(L, 1); // title - for (int i = 1; i <= lua_rawlen(L, -1); i++) { + for (size_t i = 1; i <= lua_rawlen(L, -1); i++) { lua_rawgeti(L, -1, i); if (lua_istable(L, -1)) { lua_getfield(L, -1, "title"); @@ -878,7 +878,7 @@ static int lui__newindex(lua_State *L) { #if GTK luaL_argcheck(L, lua_istable(L, 3), 3, "table of menus expected"); GtkWidget *new_menubar = gtk_menu_bar_new(); // TODO: this leaks on error - for (int i = 1; i <= lua_rawlen(L, 3); i++) { + for (size_t i = 1; i <= lua_rawlen(L, 3); i++) { lua_rawgeti(L, 3, i); luaL_argcheck(L, lua_isuserdata(L, -1), 3, "table of menus expected"); GtkWidget *menu_item = (GtkWidget *)lua_touserdata(L, -1); @@ -974,15 +974,15 @@ static void lL_gotodoc(lua_State *L, Scintilla *view, int n, int relative) { l_pushdoc(L, SS(view, SCI_GETDOCPOINTER, 0, 0)), lua_gettable(L, -2); n = lua_tointeger(L, -1) + n; lua_pop(L, 1); // index - if (n > lua_rawlen(L, -1)) + if (n > (int)lua_rawlen(L, -1)) n = 1; else if (n < 1) n = lua_rawlen(L, -1); lua_rawgeti(L, -1, n); } else { - luaL_argcheck(L, (n > 0 && n <= lua_rawlen(L, -1)) || n == -1, 2, + luaL_argcheck(L, (n > 0 && n <= (int)lua_rawlen(L, -1)) || n == -1, 2, "no Buffer exists at that index"); - lua_rawgeti(L, -1, (n > 0) ? n : lua_rawlen(L, -1)); + lua_rawgeti(L, -1, (n > 0) ? n : (int)lua_rawlen(L, -1)); } sptr_t doc = l_todoc(L, -1); SS(view, SCI_SETDOCPOINTER, 0, doc), sync_tabbar(); @@ -1020,7 +1020,7 @@ static void register_command_entry_doc() { */ static void lL_removedoc(lua_State *L, sptr_t doc) { lua_getfield(L, LUA_REGISTRYINDEX, "ta_views"); - for (int i = 1; i <= lua_rawlen(L, -1); i++) { + for (size_t i = 1; i <= lua_rawlen(L, -1); i++) { lua_rawgeti(L, -1, i); Scintilla *view = l_toview(L, -1); if (doc == SS(view, SCI_GETDOCPOINTER, 0, 0)) lL_gotodoc(L, view, -1, TRUE); @@ -1029,7 +1029,7 @@ static void lL_removedoc(lua_State *L, sptr_t doc) { lua_pop(L, 1); // views lua_newtable(L); lua_getfield(L, LUA_REGISTRYINDEX, "ta_buffers"); - for (int i = 1; i <= lua_rawlen(L, -1); i++) { + for (size_t i = 1; i <= lua_rawlen(L, -1); i++) { lua_rawgeti(L, -1, i); if (doc != l_todoc(L, -1)) { lua_getfield(L, -1, "doc_pointer"); @@ -1451,24 +1451,28 @@ static int ltimeout(lua_State *L) { /** `string.iconv()` Lua function. */ static int lstring_iconv(lua_State *L) { size_t inbytesleft = 0; +#if !_WIN32 char *inbuf = (char *)luaL_checklstring(L, 1, &inbytesleft); +#else + const char *inbuf = luaL_checklstring(L, 1, &inbytesleft); +#endif const char *to = luaL_checkstring(L, 2), *from = luaL_checkstring(L, 3); iconv_t cd = iconv_open(to, from); if (cd != (iconv_t)-1) { - char *outbuf = malloc(inbytesleft + 1), *outbufp = outbuf; + char *outbuf = malloc(inbytesleft + 1), *p = outbuf; size_t outbytesleft = inbytesleft, bufsize = inbytesleft; int n = 1; // concat this many converted strings - while (iconv(cd, &inbuf, &inbytesleft, &outbufp, &outbytesleft) == -1) + while (iconv(cd, &inbuf, &inbytesleft, &p, &outbytesleft) == (size_t)-1) if (errno == E2BIG) { // Buffer was too small to store converted string. Push the partially // converted string for later concatenation. - lua_checkstack(L, 2), lua_pushlstring(L, outbuf, outbufp - outbuf), n++; - outbufp = outbuf, outbytesleft = bufsize; + lua_checkstack(L, 2), lua_pushlstring(L, outbuf, p - outbuf), n++; + p = outbuf, outbytesleft = bufsize; } else { free(outbuf), iconv_close(cd); luaL_error(L, "conversion failed"); } - lua_pushlstring(L, outbuf, outbufp - outbuf); + lua_pushlstring(L, outbuf, p - outbuf); lua_concat(L, n); free(outbuf), iconv_close(cd); } else luaL_error(L, "invalid encoding(s)"); @@ -1629,7 +1633,7 @@ static int w_keypress(GtkWidget*_, GdkEventKey *event, void*__) { static void lL_removeview(lua_State *L, Scintilla *view) { lua_newtable(L); lua_getfield(L, LUA_REGISTRYINDEX, "ta_views"); - for (int i = 1; i <= lua_rawlen(L, -1); i++) { + for (size_t i = 1; i <= lua_rawlen(L, -1); i++) { lua_rawgeti(L, -1, i); if (view != l_toview(L, -1)) { lua_getfield(L, -1, "widget_pointer"); @@ -1717,7 +1721,7 @@ static void l_close(lua_State *L) { closing = TRUE; while (unsplit_view(focused_view)) ; // need space to fix compiler warning lua_getfield(L, LUA_REGISTRYINDEX, "ta_buffers"); - for (int i = 1; i <= lua_rawlen(L, -1); i++) + for (size_t i = 1; i <= lua_rawlen(L, -1); i++) lua_rawgeti(L, -1, i), delete_buffer(l_todoc(L, -1)), lua_pop(L, 1); lua_pop(L, 1); // buffers scintilla_delete(focused_view), scintilla_delete(dummy_view); @@ -2385,7 +2389,7 @@ int main(int argc, char **argv) { unsigned long cmd; termkey_interpret_csi(ta_tk, &key, args, &nargs, &cmd); lua_newtable(lua); - for (int i = 0; i < nargs; i++) + for (size_t i = 0; i < nargs; i++) lua_pushinteger(lua, args[i]), lua_rawseti(lua, -2, i + 1); lL_event(lua, "csi", LUA_TNUMBER, cmd, LUA_TTABLE, luaL_ref(lua, LUA_REGISTRYINDEX), -1); @@ -2438,6 +2442,7 @@ int main(int argc, char **argv) { #endif free(textadept_home); + return 0; } #if (_WIN32 && !CURSES) -- cgit v1.2.3