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


Groups > comp.unix.programmer > #1107

Re: C Code "sanity checking" tools

From Nomen Nescio <nobody@dizum.com>
Newsgroups comp.unix.programmer
Subject Re: C Code "sanity checking" tools
References <yw1xwremsyc3.fsf@unicorn.mansr.com>
Message-ID <054525e85fdfd2050bfde744d70a0627@dizum.com> (permalink)
Date 2011-08-10 12:29 +0200
Organization mail2news@dizum.com

Show all headers | View raw


Måns Rullgård <mans@mansr.com> wrote:

> And Ada expects the compiler to take responsibility.  Do you fully trust
> those who wrote the compiler and runtime support?
> 

No, but I'll take the assistance. Here are two scenarios. The first one is
analagous to the C program posted. Ada flags the error the OP asked about.

-*- mode: compilation; default-directory: "~/" -*-
Compilation started at Tue Aug 09 08:34:14

GNAT 4.3.3
Copyright 1992-2007, Free Software Foundation, Inc.


Compiling: mystring.adb (source file time stamp: 2011-08-09 08:34:14)

     1. with Ada.Text_IO; use Ada.Text_IO;
     2.
     3. procedure Mystring is
     4.    Mystring : String(1 .. 5);
           |
        >>> warning: variable "Mystring" is read but never assigned

     5.    
     6. begin
     7.    Put_Line("String: " & Mystring);
     8. end Mystring;

 8 lines: No errors, 1 warning

Compilation finished at Tue Aug 09 08:34:15

 --
 --

This one shows a common error that would result in a nice segfault or other
nasty failure in C but is flagged at compilation time in Ada and during
runtime by Ada. True this example will be flagged by most C compilers but if
you separate the declaration from the assignment it won't be. Ada will not
let you hurt yourself in this kind of scenario.

-*- mode: compilation; default-directory: "~/" -*-
Compilation started at Tue Aug 09 08:37:37

GNAT 4.3.3
Copyright 1992-2007, Free Software Foundation, Inc.


Compiling: mystring.adb (source file time stamp: 2011-08-09 08:37:37)

     1. with Ada.Text_IO; use Ada.Text_IO;
     2.
     3. procedure Mystring is
     4.    Mystring : String(1 .. 5) := "Hello!";
                                        1       3
        >>> warning: wrong length for array of subtype of "Standard.String" defined at line 4
        >>> warning: "Constraint_Error" will be raised at run time

     5.
     6.
     7. begin
     8.    Put_Line("String: " & Mystring);
     9. end Mystring;

 9 lines: No errors, 2 warnings

Compilation finished at Tue Aug 09 08:37:38

ada@host:~$ ./mystring

raised CONSTRAINT_ERROR : mystring.adb:4 length check failed

Back to comp.unix.programmer | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread


Thread

C Code "sanity checking" tools Martin Crouch <spamspamspam@spaml.com> - 2011-08-08 12:00 +0100
  Re: C Code "sanity checking" tools Richard Kettlewell <rjk@greenend.org.uk> - 2011-08-08 12:09 +0100
    Re: C Code "sanity checking" tools Fritz Wuehler <fritz@spamexpire-201108.rodent.frell.theremailer.net> - 2011-08-09 08:50 +0200
      Re: C Code "sanity checking" tools Måns Rullgård <mans@mansr.com> - 2011-08-09 10:55 +0100
        Re: C Code "sanity checking" tools Ben Bacarisse <ben.usenet@bsb.me.uk> - 2011-08-09 14:15 +0100
        Re: C Code "sanity checking" tools Nomen Nescio <nobody@dizum.com> - 2011-08-10 01:58 +0200
        Re: C Code "sanity checking" tools Nomen Nescio <nobody@dizum.com> - 2011-08-10 12:29 +0200
      Re: C Code "sanity checking" tools Rainer Weikusat <rweikusat@mssgmbh.com> - 2011-08-09 14:17 +0100
        Re: C Code "sanity checking" tools Keith Thompson <kst-u@mib.org> - 2011-08-09 09:17 -0700
          Re: C Code "sanity checking" tools Rainer Weikusat <rweikusat@mssgmbh.com> - 2011-08-09 17:36 +0100
            Re: C Code "sanity checking" tools Keith Thompson <kst-u@mib.org> - 2011-08-09 12:19 -0700
              Re: C Code "sanity checking" tools Rainer Weikusat <rweikusat@mssgmbh.com> - 2011-08-09 20:36 +0100
                Re: C Code "sanity checking" tools Michael Press <rubrum@pacbell.net> - 2011-08-09 19:24 -0700
                Re: C Code "sanity checking" tools Rainer Weikusat <rweikusat@mssgmbh.com> - 2011-08-10 10:27 +0100
                Re: C Code "sanity checking" tools Rainer Weikusat <rweikusat@mssgmbh.com> - 2011-08-10 14:01 +0100
                Re: C Code "sanity checking" tools "io_x" <a@b.c.invalid> - 2011-08-13 09:42 +0200
                Re: C Code "sanity checking" tools Keith Thompson <kst-u@mib.org> - 2011-08-13 16:04 -0700
                Re: C Code "sanity checking" tools Rainer Weikusat <rweikusat@mssgmbh.com> - 2011-08-14 19:46 +0100
  Re: C Code "sanity checking" tools Ian Collins <ian-news@hotmail.com> - 2011-08-08 23:12 +1200
    Re: C Code "sanity checking" tools Ben Bacarisse <ben.usenet@bsb.me.uk> - 2011-08-08 15:35 +0100
      Re: C Code "sanity checking" tools Martin Crouch <spamspamspam@spaml.com> - 2011-08-08 16:05 +0100
        Re: C Code "sanity checking" tools Ben Bacarisse <ben.usenet@bsb.me.uk> - 2011-08-08 22:57 +0100
          Re: C Code "sanity checking" tools Måns Rullgård <mans@mansr.com> - 2011-08-08 23:32 +0100
      Re: C Code "sanity checking" tools Ian Collins <ian-news@hotmail.com> - 2011-08-09 08:03 +1200
        Re: C Code "sanity checking" tools Ben Bacarisse <ben.usenet@bsb.me.uk> - 2011-08-08 22:51 +0100
          Re: C Code "sanity checking" tools Ian Collins <ian-news@hotmail.com> - 2011-08-09 10:01 +1200
    Re: C Code "sanity checking" tools jt@toerring.de (Jens Thoms Toerring) - 2011-08-08 22:06 +0000
      Re: C Code "sanity checking" tools Ian Collins <ian-news@hotmail.com> - 2011-08-09 10:18 +1200
        Re: C Code "sanity checking" tools jt@toerring.de (Jens Thoms Toerring) - 2011-08-08 23:25 +0000
  Re: C Code "sanity checking" tools Nobody <nobody@nowhere.com> - 2011-08-08 14:01 +0100
    Re: C Code "sanity checking" tools Måns Rullgård <mans@mansr.com> - 2011-08-08 14:47 +0100
      Re: C Code "sanity checking" tools Martin Crouch <spamspamspam@spaml.com> - 2011-08-08 16:08 +0100
        Re: C Code "sanity checking" tools Marc <marc.glisse@gmail.com> - 2011-08-08 15:39 +0000
      Re: C Code "sanity checking" tools William Ahern <william@wilbur.25thandClement.com> - 2011-08-08 10:20 -0700
      Re: C Code "sanity checking" tools Nobody <nobody@nowhere.com> - 2011-08-09 00:59 +0100
  Re: C Code "sanity checking" tools mathog <dmathog@gmail.com> - 2011-08-08 08:48 -0700

csiph-web