Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.c > #140340

Re: Distributing C as headers.

Path csiph.com!eternal-september.org!feeder.eternal-september.org!reader01.eternal-september.org!.POSTED!not-for-mail
From Keith Thompson <kst-u@mib.org>
Newsgroups comp.lang.c
Subject Re: Distributing C as headers.
Date Sun, 27 Jan 2019 16:59:39 -0800
Organization None to speak of
Lines 51
Message-ID <lnr2cxy4uc.fsf@kst-u.example.com> (permalink)
References <3719d4fa-cf75-4a85-9255-b3f961a649c1@googlegroups.com> <dbefaf2e-6e7a-4390-9260-09f5254a801f@googlegroups.com> <q2fhlg$n98$1@news.xmission.com> <5c4b5064$0$21586$426a74cc@news.free.fr> <q2fli0$pb4$1@news.xmission.com> <1bh8dw2l5r.fsf@pfeifferfamily.net> <5c4c1691$0$21610$426a74cc@news.free.fr> <1bwomr17cp.fsf@pfeifferfamily.net> <m24l9vf6zq.fsf@despina.home> <lnd0ojyu7p.fsf@kst-u.example.com> <m2o983drbb.fsf@despina.home> <ln8sz7yrq4.fsf@kst-u.example.com> <m2imybdp04.fsf@despina.home> <q2l6r5$suk$1@dont-email.me> <m2bm41ek17.fsf@despina.home> <%Hr3E.90867$nC1.33629@fx04.am4> <m27eepeire.fsf@despina.home>
Mime-Version 1.0
Content-Type text/plain; charset=us-ascii
Injection-Info reader02.eternal-september.org; posting-host="6e9d60f1a86f6adea14a7c4a73c06923"; logging-data="8595"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+HVsoWOU79ZvF37UPI7oii"
User-Agent Gnus/5.13 (Gnus v5.13) Emacs/23.1 (gnu/linux)
Cancel-Lock sha1:S0AVZJYuvVfXaNWs2rYzteTbiH4= sha1:v5U3rmcnBo2YfOu4Jy8v1IFwlHU=
Xref csiph.com comp.lang.c:140340

Show key headers only | View raw


"Pascal J. Bourguignon" <pjb@informatimago.com> writes:
[...]
> A lot of C functions take a pointer and a size (or a length; Hello
> off-by-one errors!).
>
> Instead they should take an object abstracting away those elements, so
> that their consistency can be ensured by the functional abstraction.
>
>
>      strncpy(dst,src,size); /* crash ensured */

No, a crash is not ensured.

Here's a complete C program that includes that line:

#include <string.h>
#include <stdio.h>
int main(void) {
    char dst[100];
    const char *src = "hello, world";
    const size_t size = sizeof dst;
    strncpy(dst,src,size);
    puts(dst);
}

It will not crash.

(I almost certainly wouldn't use strncpy myself, but that's not
the point.  It's certainly possible to use strncpy in a way that
will cause a program to crash; that also is not the point.)

>      string_copy(dst,src); /* no crash possible, because string_copy
>                               with handle all the cases, given
>                               src->characters, src->length and
>                               dst->characters, dst->allocated_size */

I don't believe there's a standard Pascal function called
"string_copy".  In fact you can simply assign strings in Pascal:

    dst := src;

What exactly are "src->characters", "src->length", and so forth?  As far
as I can tell, Pascal doesn't use that syntax.

You assert that your string_copy procedure can't crash, but you haven't
shown us its implementation.

-- 
Keith Thompson (The_Other_Keith) kst-u@mib.org  <http://www.ghoti.net/~kst>
Will write code for food.
void Void(void) { Void(); } /* The recursive call of the void */

Back to comp.lang.c | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread


Thread

Distributing C as headers. Malcolm McLean <malcolm.arthur.mclean@gmail.com> - 2019-01-25 07:23 -0800
  Re: Distributing C as headers. Thiago Adams <thiago.adams@gmail.com> - 2019-01-25 07:31 -0800
    Re: Distributing C as headers. Malcolm McLean <malcolm.arthur.mclean@gmail.com> - 2019-01-25 07:33 -0800
      Re: Distributing C as headers. Mateusz Viste <mateusz@wont.tell> - 2019-01-25 15:42 +0000
      Re: Distributing C as headers. gazelle@shell.xmission.com (Kenny McCormack) - 2019-01-25 17:40 +0000
        Re: Distributing C as headers. Thiago Adams <thiago.adams@gmail.com> - 2019-01-25 09:59 -0800
          Re: Distributing C as headers. Thiago Adams <thiago.adams@gmail.com> - 2019-01-25 10:01 -0800
          Re: Distributing C as headers. David Brown <david.brown@hesbynett.no> - 2019-01-25 22:17 +0100
            Re: Distributing C as headers. Bart <bc@freeuk.com> - 2019-01-25 21:33 +0000
        Re: Distributing C as headers. Mateusz Viste <mateusz@wont.tell> - 2019-01-25 18:07 +0000
          Re: Distributing C as headers. gazelle@shell.xmission.com (Kenny McCormack) - 2019-01-25 18:46 +0000
            Re: Distributing C as headers. Joe Pfeiffer <pfeiffer@cs.nmsu.edu> - 2019-01-25 19:43 -0700
              Re: Distributing C as headers. Mateusz Viste <mateusz@wont.tell> - 2019-01-26 08:13 +0000
                Re: Distributing C as headers. Joe Pfeiffer <pfeiffer@cs.nmsu.edu> - 2019-01-26 13:39 -0700
                Re: Distributing C as headers. Mateusz Viste <mateusz@wont.tell> - 2019-01-26 21:00 +0000
                Re: Distributing C as headers. "Pascal J. Bourguignon" <pjb@informatimago.com> - 2019-01-26 22:29 +0100
                Re: Distributing C as headers. nobody@example.org (Scott) - 2019-01-27 04:56 +0000
                Re: Distributing C as headers. Dan Purgert <dan@djph.net> - 2019-01-27 11:36 +0000
                Re: Distributing C as headers. Tim Rentsch <tr.17687@z991.linuxsc.com> - 2019-02-25 12:26 -0800
                Re: Distributing C as headers. "Jason C. McDonald" <indeliblebluepen@gmail.com> - 2019-02-28 19:52 +0000
                Re: Distributing C as headers. Lew Pitcher <lew.pitcher@digitalfreehold.ca> - 2019-02-28 15:04 -0500
                Re: Distributing C as headers. "Pascal J. Bourguignon" <pjb@informatimago.com> - 2019-02-28 21:40 +0100
                Re: Distributing C as headers. James Kuyper <jameskuyper@alumni.caltech.edu> - 2019-02-28 13:57 -0800
                Re: Distributing C as headers. Jorgen Grahn <grahn+nntp@snipabacken.se> - 2019-01-27 13:33 +0000
                Re: Distributing C as headers. David Brown <david.brown@hesbynett.no> - 2019-01-27 15:06 +0100
                Re: Distributing C as headers. luser droog <luser.droog@gmail.com> - 2019-01-26 13:01 -0800
                Re: Distributing C as headers. "Pascal J. Bourguignon" <pjb@informatimago.com> - 2019-01-26 22:30 +0100
                Re: Distributing C as headers. Jorgen Grahn <grahn+nntp@snipabacken.se> - 2019-02-02 09:27 +0000
                Re: Distributing C as headers. "Pascal J. Bourguignon" <pjb@informatimago.com> - 2019-01-26 22:23 +0100
                Re: Distributing C as headers. Keith Thompson <kst-u@mib.org> - 2019-01-26 13:39 -0800
                Re: Distributing C as headers. "Pascal J. Bourguignon" <pjb@informatimago.com> - 2019-01-26 22:47 +0100
                Re: Distributing C as headers. Keith Thompson <kst-u@mib.org> - 2019-01-26 14:33 -0800
                Re: Distributing C as headers. "Pascal J. Bourguignon" <pjb@informatimago.com> - 2019-01-26 23:37 +0100
                Re: Distributing C as headers. Keith Thompson <kst-u@mib.org> - 2019-01-26 15:09 -0800
                Re: Distributing C as headers. David Brown <david.brown@hesbynett.no> - 2019-01-27 15:11 +0100
                Re: Distributing C as headers. James Kuyper <jameskuyper@alumni.caltech.edu> - 2019-01-27 16:12 -0500
                Re: Distributing C as headers. "Pascal J. Bourguignon" <pjb@informatimago.com> - 2019-01-28 00:51 +0100
                Re: Distributing C as headers. Bart <bc@freeuk.com> - 2019-01-28 00:06 +0000
                Re: Distributing C as headers. Bart <bc@freeuk.com> - 2019-01-28 00:18 +0000
                Re: Distributing C as headers. Ben Bacarisse <ben.usenet@bsb.me.uk> - 2019-01-28 01:12 +0000
                Re: Distributing C as headers. Bart <bc@freeuk.com> - 2019-01-28 01:35 +0000
                Re: Distributing C as headers. Ben Bacarisse <ben.usenet@bsb.me.uk> - 2019-01-28 02:19 +0000
                Re: Distributing C as headers. Bart <bc@freeuk.com> - 2019-01-28 10:40 +0000
                Re: Distributing C as headers. "Pascal J. Bourguignon" <pjb@informatimago.com> - 2019-01-28 12:22 +0100
                Re: Distributing C as headers. "Pascal J. Bourguignon" <pjb@informatimago.com> - 2019-01-28 12:21 +0100
                Re: Distributing C as headers. Malcolm McLean <malcolm.arthur.mclean@gmail.com> - 2019-01-28 04:03 -0800
                Re: Distributing C as headers. David Brown <david.brown@hesbynett.no> - 2019-01-28 13:23 +0100
                Re: Distributing C as headers. Keith Thompson <kst-u@mib.org> - 2019-01-28 11:16 -0800
                Re: Distributing C as headers. David Brown <david.brown@hesbynett.no> - 2019-01-28 21:08 +0100
                Re: Distributing C as headers. "Pascal J. Bourguignon" <pjb@informatimago.com> - 2019-01-28 01:19 +0100
                Re: Distributing C as headers. Keith Thompson <kst-u@mib.org> - 2019-01-27 16:59 -0800
                Re: Distributing C as headers. Keith Thompson <kst-u@mib.org> - 2019-01-27 16:33 -0800
                Re: Distributing C as headers. "Pascal J. Bourguignon" <pjb@informatimago.com> - 2019-01-28 01:35 +0100
                Re: Distributing C as headers. Keith Thompson <kst-u@mib.org> - 2019-01-27 17:20 -0800
                Re: Distributing C as headers. James Kuyper <jameskuyper@alumni.caltech.edu> - 2019-01-27 22:50 -0500
                Re: Distributing C as headers. David Brown <david.brown@hesbynett.no> - 2019-01-28 06:52 +0100
                Re: Distributing C as headers. Bart <bc@freeuk.com> - 2019-01-28 10:55 +0000
                Re: Distributing C as headers. "Pascal J. Bourguignon" <pjb@informatimago.com> - 2019-01-28 12:26 +0100
                Re: Distributing C as headers. David Brown <david.brown@hesbynett.no> - 2019-01-28 13:27 +0100
                Re: Distributing C as headers. David Brown <david.brown@hesbynett.no> - 2019-01-28 13:26 +0100
                Re: Distributing C as headers. "Pascal J. Bourguignon" <pjb@informatimago.com> - 2019-01-28 14:03 +0100
                Re: Distributing C as headers. Keith Thompson <kst-u@mib.org> - 2019-01-28 11:12 -0800
                Re: Distributing C as headers. "Pascal J. Bourguignon" <pjb@informatimago.com> - 2019-01-28 12:25 +0100
                Re: Distributing C as headers. David Brown <david.brown@hesbynett.no> - 2019-01-28 13:33 +0100
                Re: Distributing C as headers. Keith Thompson <kst-u@mib.org> - 2019-01-28 11:20 -0800
                Re: Distributing C as headers. David Brown <david.brown@hesbynett.no> - 2019-01-28 21:11 +0100
                Re: Distributing C as headers. scott@slp53.sl.home (Scott Lurndal) - 2019-01-28 21:12 +0000
                Re: Distributing C as headers. David Brown <david.brown@hesbynett.no> - 2019-01-28 23:06 +0100
                Re: Distributing C as headers. David Brown <david.brown@hesbynett.no> - 2019-01-27 15:02 +0100
    Re: Distributing C as headers. "Pascal J. Bourguignon" <pjb@informatimago.com> - 2019-01-25 17:51 +0100
    Re: Distributing C as headers. fir <profesor.fir@gmail.com> - 2019-01-25 14:28 -0800

csiph-web