Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S262385AbTGKOh4 (ORCPT ); Fri, 11 Jul 2003 10:37:56 -0400 Received: (majordomo@vger.kernel.org) by vger.kernel.org id S262498AbTGKOh4 (ORCPT ); Fri, 11 Jul 2003 10:37:56 -0400 Received: from chaos.analogic.com ([204.178.40.224]:11648 "EHLO chaos.analogic.com") by vger.kernel.org with ESMTP id S262385AbTGKOhx (ORCPT ); Fri, 11 Jul 2003 10:37:53 -0400 Date: Fri, 11 Jul 2003 10:52:50 -0400 (EDT) From: "Richard B. Johnson" X-X-Sender: root@chaos Reply-To: root@chaos.analogic.com To: "David D. Hagood" cc: hzhong@cisco.com, "'Alan Stern'" , Linux kernel Subject: Re: Style question: Should one check for NULL pointers? In-Reply-To: <3F0EC5EF.7090002@sktc.net> Message-ID: References: <01c701c34766$4706cc50$743147ab@amer.cisco.com> <3F0EC5EF.7090002@sktc.net> MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII Sender: linux-kernel-owner@vger.kernel.org X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 1843 Lines: 52 On Fri, 11 Jul 2003, David D. Hagood wrote: > Hua Zhong wrote: > > > Not always true. In some cases you know how to handle: just return > > without doing anyting. > > That is NOT an error condition - the API specifically allows NULL to be > passed in, and specifically states that no action will be taken in that > case. > > But consider the following code: > > sscanf(0,0); > > That IS an error condition - both the string to scan and the format > string are NULL. In this case sscanf should return EITHER 0 (no items > matched) or better still -1 (error). > But it does neither. Instead, it seg-faults your code! The problem lies with the original question. The question referred to "Style" (look at the subject-line). It is not a question about style, but a question about utility and design. Style has nothing to do with it. If you are writing code for an embedded system, the code must always run even if RAM got trashed from alpha particles or EMP. In that case, you trap every possible condition and force a restart off a hardware timer, refreshing everything in RAM from PROM or NVRAM. If you are writing code to examine the contents of sys_errlist[], prior to adding another error-code, then you don't check anything and it's file-name is probably a.out, compiled from xxx.c. So, the extent to which one checks for exceptions and provides utility for handling exceptions depends upon the code design, not it's style. Cheers, Dick Johnson Penguin : Linux version 2.4.20 on an i686 machine (797.90 BogoMips). Why is the government concerned about the lunatic fringe? Think about it. - To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/