From nobody@FreeBSD.org  Wed Sep 19 13:18:38 2012
Return-Path: <nobody@FreeBSD.org>
Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34])
	by hub.freebsd.org (Postfix) with ESMTP id 0A37E1065670
	for <freebsd-gnats-submit@FreeBSD.org>; Wed, 19 Sep 2012 13:18:38 +0000 (UTC)
	(envelope-from nobody@FreeBSD.org)
Received: from red.freebsd.org (red.freebsd.org [IPv6:2001:4f8:fff6::22])
	by mx1.freebsd.org (Postfix) with ESMTP id D0E9C8FC15
	for <freebsd-gnats-submit@FreeBSD.org>; Wed, 19 Sep 2012 13:18:37 +0000 (UTC)
Received: from red.freebsd.org (localhost [127.0.0.1])
	by red.freebsd.org (8.14.5/8.14.5) with ESMTP id q8JDIbiJ025742
	for <freebsd-gnats-submit@FreeBSD.org>; Wed, 19 Sep 2012 13:18:37 GMT
	(envelope-from nobody@red.freebsd.org)
Received: (from nobody@localhost)
	by red.freebsd.org (8.14.5/8.14.5/Submit) id q8JDIbOp025741;
	Wed, 19 Sep 2012 13:18:37 GMT
	(envelope-from nobody)
Message-Id: <201209191318.q8JDIbOp025741@red.freebsd.org>
Date: Wed, 19 Sep 2012 13:18:37 GMT
From: Erik Cederstrand <erik@cederstrand.dk>
To: freebsd-gnats-submit@FreeBSD.org
Subject: Enable assert()s in ncurses
X-Send-Pr-Version: www-3.1
X-GNATS-Notify:

>Number:         171777
>Category:       kern
>Synopsis:       [ncurses] [patch] 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:  Sat Oct 06 03:36:37 UTC 2012
>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:
