From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on polar.synack.me X-Spam-Level: X-Spam-Status: No, score=0.2 required=5.0 tests=BAYES_00,INVALID_MSGID, REPLYTO_WITHOUT_TO_CC autolearn=no autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 109fba,baaf5f793d03d420 X-Google-Attributes: gid109fba,public X-Google-Thread: 103376,97188312486d4578 X-Google-Attributes: gid103376,public X-Google-Thread: fc89c,97188312486d4578 X-Google-Attributes: gidfc89c,public X-Google-Thread: 1014db,6154de2e240de72a X-Google-Attributes: gid1014db,public From: Arkady Belousov Subject: Re: What's the best language to start with? [was: Re: Should I learn C or Pascal?] Date: 1996/09/03 Message-ID: <322D08A6.7AC0@munic.msk.su>#1/1 X-Deja-AN: 178220212 references: <31FBC584.4188@ivic.qc.ca> <01bb83f5$923391e0$87ee6fce@timpent.airshields.com> <4uah1k$b2o@solutions.solon.com> <01bb853b$ca4c8e00$87ee6fce@timpent.airshields.com> <4udb2o$7io@solutions.solon.com> <01bb8569$9910dca0$87ee6fce@timpent.airshields.com> <4urqam$r9u@goanna.cs.rmit.edu.au> <01bb8b84$200baa80$87ee6fce@timpent.airshields.com> <4vbbf6$g0a@goanna.cs.rmit.edu.au> <01bb8f18$713e0e60$32ee6fce@timhome2> <4vroh3$17f@goanna.cs.rmit.edu.au> <50650h$rek@goanna.cs.rmit.edu.au> content-type: text/plain; charset=koi8-r organization: CIT of MMO mime-version: 1.0 reply-to: ark@munic.msk.su newsgroups: comp.lang.c,comp.lang.c++,comp.unix.programmer,comp.lang.ada x-mailer: Mozilla 3.0b8Gold (Win16; I) Date: 1996-09-03T00:00:00+00:00 List-Id: Hello! Richard A. O'Keefe wrote: > Consider > char *dupcat(char const *a, char const *b) { > char *result = malloc(strlen(a) + strlen(b) + 1); > assert(result != 0); > memcpy(result, a, strlen(a)); > memcpy(result + strlen(a), b, strlen(b)); > memcpy(result + strlen(a) + strlen(b), "", 1); > return result; > } > I repeat, this is NOT the way I would normally write it. > I contend that it is _inefficient_ but not "stupid". > If a malicious (and not strictly conforming) signal handler smashes > NBTS(a) or NBTS(b), then you have worse problems than just possible > changes to strlen(). Manually saving the numbers won't protect you > from the fact that the null-terminated-byte-strings have changed, > so that the function result (as an NBTS) is not the concatenation > of its NBTS arguments. For ease controlling such situation standard have "volatile" keyword. So you are right, I think.