Skip site navigation (1)Skip section navigation (2)
Date:      Sun, 10 Mar 1996 00:03:20 +1030 (CST)
From:      Michael Smith <msmith@atrad.adelaide.edu.au>
To:        gurney_j@resnet.uoregon.edu
Cc:        hackers@FreeBSD.org, dwhite@resnet.uoregon.edu
Subject:   Re: seg fault and strlen
Message-ID:  <199603091333.AAA13154@genesis.atrad.adelaide.edu.au>
In-Reply-To: <Pine.BSF.3.91.960309013951.7129A-100000@nike.efn.org> from "John-Mark Gurney" at Mar 9, 96 01:41:26 am

next in thread | previous in thread | raw e-mail | index | archive | help
John-Mark Gurney stands accused of saying:
> 
> I'm not sure this is the best place to put it... but is it ok for strlen 
> to seg fault your program when you pass a null pointer to it?  just 
> wondering... TTYL...

This one's been done nearly to death in the past. 8)

The answer is, yes.  It's illegal to pass a null pointer to strlen.  A
nonexistent string does not have a length, and it's an error for your
program to try to determine it.

Library functions shouldn't be doing your error checking for you.  If they
did, performance would suck.  As designer of your code, you are in the
best position to determine where error conditions may occur, and to trap 
them  appropriately..

If you want to argue about this, go to comp.lang.c, and fish out the ol'
asbestos 8)

> John-Mark

-- 
]] Mike Smith, Software Engineer        msmith@atrad.adelaide.edu.au    [[
]] Genesis Software                     genesis@atrad.adelaide.edu.au   [[
]] High-speed data acquisition and      (GSM mobile) 0411-222-496       [[
]] realtime instrument control          (ph/fax)  +61-8-267-3039        [[
]] Collector of old Unix hardware.      "Where are your PEZ?" The Tick  [[



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?199603091333.AAA13154>