comp.lang.ada
 help / color / mirror / Atom feed
From: tmoran@acm.org
Subject: Re: Constraint Error
Date: Thu, 30 Sep 2004 01:11:17 GMT
Date: 2004-09-30T01:11:17+00:00	[thread overview]
Message-ID: <R2J6d.180295$3l3.739@attbi_s03> (raw)
In-Reply-To: cjfg8e$g6i$00$1@news.t-online.com

> m2:=Messages.Create("This is a second test");
will raise Constraint_Error because you attempt to store its 21 characters
into M.Text, which is a 20 character string.  Ada is preventing a buffer
overflow error.

> m1:=Messages.Create("This is a test");
raises Constraint_Error because you attempt to store a 14 character
string into a 20 character M.Text  If you had said, for instance,
  M.Text(1 .. Str'length) := Str;
then it would have stored into the first 14 characters, leaving junk
in the next 6 and no way for a later user of M.Text to know which,
if any, of its characters are non-junk.
Or
  M.Text := Str & (Str'length+1 .. M.Text'length => ' ');
would fill in any unused characters with ' ', which might be what
you would like.

To assign an array (or String, which is just an array of characters)
to another array, their sizes must match.  If they don't match, you
will need to truncate, pad, or just partially fill, as needed.  In
that case you probably want to use a counter or special terminating
character, to remember the "actual" size of the string in M.Text

In the particular case of varying length strings, of course, it would
be easiest to just use Ada.Strings.Bounded or Ada.Strings.Unbounded



  parent reply	other threads:[~2004-09-30  1:11 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2004-09-29 23:24 Constraint Error Rick Santa-Cruz
2004-09-30  0:42 ` Jeffrey Carter
2004-09-30  0:42 ` Stephen Leake
2004-09-30  1:11 ` tmoran [this message]
2004-09-30 13:47 ` John A. S. Rowlands
  -- strict thread matches above, loose matches on Subject: below --
1999-04-07  0:00 Constraint error Nirmala Bhupathi
1999-04-07  0:00 ` Matthew Heaney
1999-04-07  0:00   ` Nirmala Bhupathi
1999-04-08  0:00     ` Matthew Heaney
1987-04-10 21:47 Constraint_Error keith
replies disabled

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox