misc/171777: Enable assert()s in ncurses

Erik Cederstrand erik at cederstrand.dk
Wed Sep 19 13:20:04 UTC 2012


>Number:         171777
>Category:       misc
>Synopsis:       Enable assert()s in ncurses
>Confidential:   no
>Severity:       non-critical
>Priority:       low
>Responsible:    freebsd-bugs
>State:          open
>Quarter:        
>Keywords:       
>Date-Required:
>Class:          sw-bug
>Submitter-Id:   current-users
>Arrival-Date:   Wed Sep 19 13:20:03 UTC 2012
>Closed-Date:
>Last-Modified:
>Originator:     Erik Cederstrand
>Release:        HEAD
>Organization:
>Environment:
>Description:
ncurses unconditionally sets NDEBUG to either 0 or 1 in code. include/assert.h disables assert()'s if NDEBUG is set, so assert()'s are never enabled in ncurses. This leads to this report http://scan.freebsd.your.org/freebsd-head/lib.ncurses.menu/2012-09-16-amd64/report-3vc5Zu.html#Path5 and ca. 25 others in ncurses.

>How-To-Repeat:

>Fix:
Fix this by removing NDEBUG from contrib/ncurses/include/ncurses_defs. The comment at the top of that file even says not to define NDEBUG there, and it's been fixed in ncurses 5.9 which is in the vendor area in SVN.

Also remove two instances in lib/ncurses where NDEBUG is set unconditionally.

The attached patch allows Clang Analyzer to reason correctly about the code. It's still possible to build ncurses without assert()s by adding -DNDEBUG to CFLAGS when building.

I'm assuming that ncurses is not performance-critical in the default use and that enabling assert()s is OK. From a user perspective, it's better to get an assertion error with the real problem than a null pointer dereference error or garbage data.

Patch attached with submission follows:

Index: lib/ncurses/ncurses/ncurses_cfg.h
===================================================================
--- lib/ncurses/ncurses/ncurses_cfg.h	(revision 240638)
+++ lib/ncurses/ncurses/ncurses_cfg.h	(working copy)
@@ -145,7 +145,6 @@
#define NCURSES_NO_PADDING 1
#define NCURSES_PATHSEP ':'
#define NCURSES_VERSION_STRING "5.7.20081102"
-#define NDEBUG 1
#define RETSIGTYPE void
#define SIG_ATOMIC_T volatile sig_atomic_t
#define SIZEOF_SIGNED_CHAR 1
Index: lib/ncurses/config.mk
===================================================================
--- lib/ncurses/config.mk	(revision 240638)
+++ lib/ncurses/config.mk	(working copy)
@@ -27,8 +27,6 @@

CFLAGS+=	-Wall

-CFLAGS+=	-DNDEBUG
-
CFLAGS+=	-DHAVE_CONFIG_H

# everyone needs this
Index: contrib/ncurses/include/ncurses_defs
===================================================================
--- contrib/ncurses/include/ncurses_defs	(revision 240638)
+++ contrib/ncurses/include/ncurses_defs	(working copy)
@@ -171,7 +171,6 @@
NCURSES_EXT_FUNCS
NCURSES_NO_PADDING
NCURSES_PATHSEP	':'
-NDEBUG
NEED_PTEM_H
NO_LEAKS
PURE_TERMINFO

>Release-Note:
>Audit-Trail:
>Unformatted:


More information about the freebsd-bugs mailing list