nano-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Nano-devel] [PATCH] fix invalid pointer casts


From: Mike Frysinger
Subject: [Nano-devel] [PATCH] fix invalid pointer casts
Date: Mon, 21 Dec 2015 23:15:40 -0500

You cannot assume sizeof(void*) == sizeof(int), because it isn't on
most 64-bit systems.  Casting it to an int can cause valid pointers
to be truncated and rejected.  Rework the code to test for the two
invalid values directly.
---
 src/nano.c | 11 +++++++----
 1 file changed, 7 insertions(+), 4 deletions(-)

diff --git a/src/nano.c b/src/nano.c
index c92a89a..88d3376 100644
--- a/src/nano.c
+++ b/src/nano.c
@@ -2716,10 +2716,13 @@ int main(int argc, char **argv)
 
 #if !defined(NANO_TINY) && defined(HAVE_KEY_DEFINED)
     /* Ask ncurses for the key codes for Control+Left and Control+Right. */
-    if ((int)tigetstr("kLFT5") > 0)
-       controlleft = key_defined(tigetstr("kLFT5"));
-    if ((int)tigetstr("kRIT5") > 0)
-       controlright = key_defined(tigetstr("kRIT5"));
+    const char *setting;
+    setting = tigetstr("kLFT5");
+    if (setting && setting != (char *)-1)
+       controlleft = key_defined(setting);
+    setting = tigetstr("kRIT5");
+    if (setting && setting != (char *)-1)
+       controlright = key_defined(setting);
 #endif
 
 #ifdef DEBUG
-- 
2.6.2




reply via email to

[Prev in Thread] Current Thread [Next in Thread]