Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Path: utzoo!mnetor!seismo!caip!clyde!cbatt!cbosgd!nitrex!cwruecmp!hal!ncoast!allbery From: allbery@ncoast.UUCP (Brandon Allbery) Newsgroups: net.unix Subject: if (pointer) command Message-ID: <1427@ncoast.UUCP> Date: Fri, 5-Sep-86 18:18:10 EDT Article-I.D.: ncoast.1427 Posted: Fri Sep 5 18:18:10 1986 Date-Received: Sat, 6-Sep-86 20:33:49 EDT References: <3325@brl-smoke.ARPA> <241@bsdpkh.UUCP> <1170@ttrdc.UUCP> Reply-To: allbery@ncoast.UUCP (Brandon Allbery) Followup-To: net.unix Organization: Cleveland Public Access UNIX (ncoast), Cleveland, OH Lines: 37 Summary: potential problems Quoted from <1170@ttrdc.UUCP> ["Re: strdup"], by levy@ttrdc.UUCP (Daniel R. Levy)... +--------------- | In article <241@bsdpkh.UUCP>, heff@bsdpkh.UUCP (Paul K Heffner) writes: | | >> /* hjb 08/25/86 */ | >> char * strdup(s) | >> char *s; | >> { | >> char *p; | >> extern char *malloc(); | >> if(p=malloc(strlen(s)+1)) strcpy(p,s); | >> return p; | >> } | | >The above code doesn't return a null if malloc fails | | It DOESN'T??? Gee, then maybe you have a busted malloc(). If malloc() | fails, it should return the null pointer. That is what is being tested in | the clause 'if(p=malloc(strlen(s)+1))'. As so many people have expounded | in net.lang.c: a null pointer is semantically the same as zero in the C | language (except for sizeof(), should pointers exist of sizes other than | sizeof(int)). +--------------- But if a pointer is 4 bits and an int is 2 bits (some 68000 implementations), you'll get spurious failures if the pointer returned by malloc is a multiple of 0x10000! ++Brandon -- ---------------- /--/ Brandon S. Allbery UUCP: decvax!cwruecmp! / / /|\/ Tridelta Industries, Inc. ncoast!tdi2!brandon ---- -------- /-++ 7350 Corporate Blvd. PHONE: +1 216 974 9210 / / /---, ---- Mentor, Ohio 44060 SYSOP: UNaXcess/ncoast / / / / / / -- HOME -- (216) 781-6201 24 hrs. / / / / / / 6615 Center St. Apt. A1-105 ARPA: ncoast!allbery% ---- -----~ ---- Mentor, Ohio 44060-4101 case.CSNET@csnet-relay