bug-ncurses
[Top][All Lists]
Advanced

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

Re: segmentation fault inside waddch_literal()


From: Tetsuo Handa
Subject: Re: segmentation fault inside waddch_literal()
Date: Sat, 17 Jul 2021 20:21:03 +0900
User-agent: Mozilla/5.0 (Windows NT 6.3; Win64; x64; rv:78.0) Gecko/20100101 Thunderbird/78.12.0

On 2021/07/16 14:41, Tetsuo Handa wrote:
> My program (which runs on Linux) is built with symbol _GNU_SOURCE defined
> in order to make Unix/Linux specific extensions visible. As a result,
> curses.h is #include'd with symbol _GNU_SOURCE defined.
> 
> When this sample is built with -D_GNU_SOURCE, segmentation fault happens.
> When this sample is built without -D_GNU_SOURCE, it seems to work fine.
> I have no idea why this makes run-time difference.
> 

I compared string data within sample1 built with _GNU_SOURCE and without 
_GNU_SOURCE,
and noticed that there are several differences.

  $ diff strings-built-with-_GNU_SOURCE strings-built-without-_GNU_SOURCE 
  13d12
  < _bkgrnd
  19d17
  < cchar_t
  21d18
  < chars
  77d73
  < ext_color
  129,130c125
  < long double
  < long long int
  ---
  > long int
  180d174
  < stddef.h
  192d185
  < /usr/lib/gcc/x86_64-mageia-linux-gnu/10/include
  199d191
  < wchar_t

It seems that the cause of this problem is "#include <curses.h>" with
symbol _GNU_SOURCE defined causes NCURSES_WIDECHAR to be defined as 1
because

  defined(_XOPEN_SOURCE_EXTENDED) || (defined(_XOPEN_SOURCE) && (_XOPEN_SOURCE 
- 0 >= 500))

is evaluated as true, and the disagreement of memory layout of data structure
definitions between this program and the library cannot be detected until
this problem occurs.

It seems that how NCURSES_WIDECHAR is defined has changed in v5_9_20111029.

----------
@@ -151,15 +151,21 @@ typedef unsigned @cf_cv_typeof_mmask_t@ mmask_t;
 
 /*
  * With XPG4, you must define _XOPEN_SOURCE_EXTENDED, it is redundant (or
- * conflicting) when _XOPEN_SOURCE is 500 or greater.
+ * conflicting) when _XOPEN_SOURCE is 500 or greater.  If NCURSES_WIDECHAR is
+ * not already defined, e.g., if the platform relies upon nonstandard feature
+ * test macros, define it at this point if the standard feature test macros
+ * indicate that it should be defined.
  */
-#undef NCURSES_WIDECHAR
-#if defined(_XOPEN_SOURCE_EXTENDED) || defined(_XPG5)
-#define NCURSES_WIDECHAR
+#ifndef NCURSES_WIDECHAR
+#if defined(_XOPEN_SOURCE_EXTENDED) || (defined(_XOPEN_SOURCE) && 
(_XOPEN_SOURCE - 0 >= 500))
+#define NCURSES_WIDECHAR 1
+#else
+#define NCURSES_WIDECHAR 0
 #endif
+#endif /* NCURSES_WIDECHAR */
 
 #include <stdarg.h>    /* we need va_list */
-#ifdef NCURSES_WIDECHAR
+#if NCURSES_WIDECHAR
 #include <stddef.h>    /* we want wchar_t */
 #endif
 
----------

Building like

  gcc -Wall -O0 -g -DCOLOR_ON -D_GNU_SOURCE -DNCURSES_WIDECHAR=0 -o sample1 
sample1.c -lncurses -ltinfo 

avoids this problem (i.e. behaves as if _GNU_SOURCE is not defined) for Mageia 
8 environment.
But I don't know whether I can add -DNCURSES_WIDECHAR=0 for other Linux 
environments.
How can I know what value my program should specify for NCURSES_WIDECHAR ?



reply via email to

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