From 560c4ab1c32eacc48f62e4176a1e9fb10ac7665b Mon Sep 17 00:00:00 2001 From: Ken Brown Date: Mon, 20 Jun 2016 23:05:12 -0400 Subject: [PATCH] Fix compiler warnings in Cygwin-w32 build * src/conf_post.h (DebPrint) [!EMACSDEBUG]: Add empty do-while loop to avoid compiler warnings about empty body of 'if' statement. * src/image.c [HAVE_NTGUI] (DefaultDepthOfScreen): Disable unused macro. (x_create_bitmap_from_data): Declare 'frame'. (x_create_bitmap_from_file): Don't declare unused variable 'dpyinfo'. * src/lisp.h (AUTO_STRING_WITH_LEN): Avoid initialization to prevent "jump-misses-init" compiler warnings. * src/w32fns.c (check_w32_winkey_state): Define and use only if WINDOWSNT. (Fx_show_tip): Declare 'f'. (Fx_file_dialog): Declare 'filter_a' only if not NTGUI_UNICODE. (w32_strerror): Use format specifier %d for sprintf argument of type int. (emacs_abort): Cast sprintf argument of type DWORD to unsigned int, and use format specifier %x, for compatibility with Cygwin. (unicode_append_menu) [NTGUI_UNICODE]: * src/w32menu.c [NTGUI_UNICODE] (get_menu_item_info) (set_menu_item_info, unicode_append_menu) (unicode_message_box): * src/menu.c [NTGUI_UNICODE] (unicode_append_menu): Define as functions rather than macros to avoid "address will always evaluate as true" compiler warnings. * src/w32font.c (w32_to_x_charset): Use format specifier %d for sprintf argument of type int. * src/w32term.c (x_draw_glyphless_glyph_string_foreground): Cast sprintf argument of type int to unsigned int to match %X format specifier. (w32_scroll_bar_handle_click): (w32_horizontal_scroll_bar_handle_click): Declare 'f'. * src/w32term.h (FRAME_DISPLAY_INFO): Explicitly discard unused argument. --- src/conf_post.h | 3 ++- src/image.c | 7 +++++-- src/lisp.h | 4 +++- src/menu.c | 4 ---- src/w32fns.c | 17 ++++++++++------- src/w32font.c | 4 ++-- src/w32menu.c | 8 ++++---- src/w32term.c | 4 +++- src/w32term.h | 2 +- 9 files changed, 30 insertions(+), 23 deletions(-) diff --git a/src/conf_post.h b/src/conf_post.h index 4459caf3f9..431b7a9d82 100644 --- a/src/conf_post.h +++ b/src/conf_post.h @@ -211,7 +211,8 @@ You lose; /* Emacs for DOS must be compiled with DJGPP */ extern void _DebPrint (const char *fmt, ...); # define DebPrint(stuff) _DebPrint stuff # else -# define DebPrint(stuff) +/* Avoid compiler warnings about empty body of 'if' statement. */ +# define DebPrint(stuff) do {} while (false) # endif #endif diff --git a/src/image.c b/src/image.c index 657852b1a8..0df415c37c 100644 --- a/src/image.c +++ b/src/image.c @@ -80,7 +80,9 @@ typedef struct w32_bitmap_record Bitmap_Record; #define PIX_MASK_DRAW 1 #define x_defined_color w32_defined_color +#if 0 /* unused */ #define DefaultDepthOfScreen(screen) (one_w32_display_info.n_cbits) +#endif #endif /* HAVE_NTGUI */ @@ -223,6 +225,7 @@ x_create_bitmap_from_data (struct frame *f, char *bits, unsigned int width, unsi #endif /* HAVE_X_WINDOWS */ #ifdef HAVE_NTGUI + Lisp_Object frame UNINIT; /* The value is not used. */ Pixmap bitmap; bitmap = CreateBitmap (width, height, FRAME_DISPLAY_INFO (XFRAME (frame))->n_planes, @@ -272,9 +275,9 @@ x_create_bitmap_from_file (struct frame *f, Lisp_Object file) { #ifdef HAVE_NTGUI return -1; /* W32_TODO : bitmap support */ -#endif /* HAVE_NTGUI */ - +#else Display_Info *dpyinfo = FRAME_DISPLAY_INFO (f); +#endif #ifdef HAVE_NS ptrdiff_t id; diff --git a/src/lisp.h b/src/lisp.h index e0eb52a84e..6a8f829546 100644 --- a/src/lisp.h +++ b/src/lisp.h @@ -4634,8 +4634,10 @@ enum STR's value is not necessarily copied. The resulting Lisp string should not be modified or made visible to user code. */ +/* Avoid initializing NAME to prevent "jump-misses-init" compiler + warnings. */ #define AUTO_STRING_WITH_LEN(name, str, len) \ - Lisp_Object name = \ + Lisp_Object name; name = \ (USE_STACK_STRING \ ? (make_lisp_ptr \ ((&(union Aligned_String) \ diff --git a/src/menu.c b/src/menu.c index e3d943e109..90bb19a2e9 100644 --- a/src/menu.c +++ b/src/menu.c @@ -42,11 +42,7 @@ along with GNU Emacs. If not, see . */ #endif /* HAVE_WINDOW_SYSTEM */ #ifdef HAVE_NTGUI -# ifdef NTGUI_UNICODE -# define unicode_append_menu AppendMenuW -# else /* !NTGUI_UNICODE */ extern AppendMenuW_Proc unicode_append_menu; -# endif /* NTGUI_UNICODE */ #endif /* HAVE_NTGUI */ #include "menu.h" diff --git a/src/w32fns.c b/src/w32fns.c index f2b438cbe0..bc9c74748d 100644 --- a/src/w32fns.c +++ b/src/w32fns.c @@ -186,11 +186,7 @@ MonitorFromWindow_Proc monitor_from_window_fn = NULL; EnumDisplayMonitors_Proc enum_display_monitors_fn = NULL; GetTitleBarInfo_Proc get_title_bar_info_fn = NULL; -#ifdef NTGUI_UNICODE -#define unicode_append_menu AppendMenuW -#else /* !NTGUI_UNICODE */ extern AppendMenuW_Proc unicode_append_menu; -#endif /* NTGUI_UNICODE */ /* Flag to selectively ignore WM_IME_CHAR messages. */ static int ignore_ime_char = 0; @@ -2406,6 +2402,7 @@ hook_w32_key (int hook, int modifier, int vkey) } } +#ifdef WINDOWSNT /* Check the current Win key pressed state. */ int check_w32_winkey_state (int vkey) @@ -2433,6 +2430,7 @@ check_w32_winkey_state (int vkey) } return 0; } +#endif /* WINDOWSNT */ /* Reset the keyboard hook state. Locking the workstation with Win-L leaves the Win key(s) "down" from the hook's point of view - the @@ -2623,8 +2621,10 @@ modifier_set (int vkey) else return (GetKeyState (vkey) & 0x1); } +#ifdef WINDOWSNT if (w32_kbdhook_active && (vkey == VK_LWIN || vkey == VK_RWIN)) return check_w32_winkey_state (vkey); +#endif if (!modifiers_recorded) return (GetKeyState (vkey) & 0x8000); @@ -7043,6 +7043,7 @@ Text larger than the specified size is clipped. */) /* Create a frame for the tooltip, and record it in the global variable tip_frame. */ + struct frame *f; /* The value is unused. */ if (NILP (tip_frame = x_create_tip_frame (FRAME_DISPLAY_INFO (f), parms))) { /* Creating the tip frame failed. */ @@ -7288,7 +7289,9 @@ value of DIR as in previous invocations; this is standard Windows behavior. */) { /* Filter index: 1: All Files, 2: Directories only */ static const wchar_t filter_w[] = L"All Files (*.*)\0*.*\0Directories\0*|*\0"; +#ifndef NTGUI_UNICODE static const char filter_a[] = "All Files (*.*)\0*.*\0Directories\0*|*\0"; +#endif Lisp_Object filename = default_filename; struct frame *f = SELECTED_FRAME (); @@ -8962,7 +8965,7 @@ w32_strerror (int error_no) --ret; buf[ret] = '\0'; if (!ret) - sprintf (buf, "w32 error %u", error_no); + sprintf (buf, "w32 error %d", error_no); return buf; } @@ -10331,8 +10334,8 @@ emacs_abort (void) but not on Windows 7. addr2line doesn't mind a missing "0x", but will be confused by an extra one. */ if (except_addr) - sprintf (buf, "\r\nException 0x%lx at this address:\r\n%p\r\n", - except_code, except_addr); + sprintf (buf, "\r\nException 0x%x at this address:\r\n%p\r\n", + (unsigned int) except_code, except_addr); if (stderr_fd >= 0) { if (except_addr) diff --git a/src/w32font.c b/src/w32font.c index b8884a50db..4d15cffb9f 100644 --- a/src/w32font.c +++ b/src/w32font.c @@ -1747,7 +1747,7 @@ w32_to_x_charset (int fncharset, char *matching) default: /* Encode numerical value of unknown charset. */ - sprintf (buf, "*-#%u", fncharset); + sprintf (buf, "*-#%d", fncharset); return buf; } @@ -1834,7 +1834,7 @@ w32_to_x_charset (int fncharset, char *matching) /* If no match, encode the numeric value. */ if (!best_match) { - sprintf (buf, "*-#%u", fncharset); + sprintf (buf, "*-#%d", fncharset); return buf; } diff --git a/src/w32menu.c b/src/w32menu.c index fecbf33a12..13296d9d85 100644 --- a/src/w32menu.c +++ b/src/w32menu.c @@ -77,10 +77,10 @@ typedef int (WINAPI * MessageBoxW_Proc) ( IN UINT type); #ifdef NTGUI_UNICODE -#define get_menu_item_info GetMenuItemInfoA -#define set_menu_item_info SetMenuItemInfoA -#define unicode_append_menu AppendMenuW -#define unicode_message_box MessageBoxW +GetMenuItemInfoA_Proc get_menu_item_info = GetMenuItemInfoA; +SetMenuItemInfoA_Proc set_menu_item_info = SetMenuItemInfoA; +AppendMenuW_Proc unicode_append_menu = AppendMenuW; +MessageBoxW_Proc unicode_message_box = MessageBoxW; #else /* !NTGUI_UNICODE */ GetMenuItemInfoA_Proc get_menu_item_info = NULL; SetMenuItemInfoA_Proc set_menu_item_info = NULL; diff --git a/src/w32term.c b/src/w32term.c index c16c8f4eec..7ef34079e3 100644 --- a/src/w32term.c +++ b/src/w32term.c @@ -1434,7 +1434,7 @@ x_draw_glyphless_glyph_string_foreground (struct glyph_string *s) { sprintf ((char *) buf, "%0*X", glyph->u.glyphless.ch < 0x10000 ? 4 : 6, - glyph->u.glyphless.ch); + (unsigned int) glyph->u.glyphless.ch); str = buf; } @@ -4198,6 +4198,7 @@ w32_scroll_bar_handle_click (struct scroll_bar *bar, W32Msg *msg, y = si.nPos; bar->dragging = 0; + struct frame *f; /* Value is not used. */ FRAME_DISPLAY_INFO (f)->last_mouse_scroll_bar_pos = msg->msg.wParam; switch (sb_event) @@ -4313,6 +4314,7 @@ w32_horizontal_scroll_bar_handle_click (struct scroll_bar *bar, W32Msg *msg, y = si.nMax - si.nPage; bar->dragging = 0; + struct frame *f; /* Value is not used. */ FRAME_DISPLAY_INFO (f)->last_mouse_scroll_bar_pos = msg->msg.wParam; switch (sb_event) diff --git a/src/w32term.h b/src/w32term.h index e134da5ea5..320477073a 100644 --- a/src/w32term.h +++ b/src/w32term.h @@ -399,7 +399,7 @@ extern struct w32_output w32term_display; #define FRAME_BASELINE_OFFSET(f) ((f)->output_data.w32->baseline_offset) /* This gives the w32_display_info structure for the display F is on. */ -#define FRAME_DISPLAY_INFO(f) (&one_w32_display_info) +#define FRAME_DISPLAY_INFO(f) ((void) (f), (&one_w32_display_info)) /* This is the `Display *' which frame F is on. */ #define FRAME_X_DISPLAY(f) (0) -- 2.39.2