comp.lang.ada
 help / color / mirror / Atom feed
From: Anton Gibbs <agibbs@dera.gov.uk>
Subject: Use of C.Strings.Value Function Considered Harmful
Date: 1999/12/03
Date: 1999-12-03T00:00:00+00:00	[thread overview]
Message-ID: <3847E5CE.4F9E@dera.gov.uk> (raw)

Dear Ada Community,

Now here is a funny thing - though I doubt whether I am the first to
experience it.

I have been passed a C structure one of whose fields purports to be a
pointer to a standard C null-terminated string. I want to copy the
string into the Ada world so I thought I would use the Value function in
B.3.1 (37):

   function Value( Item : in chars_ptr ) return String;

which is defined as being equivalent to:

   To_Ada( Value( Item ), Trim_Nul => False );

This works fine except that I want to guard against the C pointer being
bad and serving me up with a potentially limitless string of rubbish. So
I thought I would use the Value function from B.3.1 (35):

   function Value( Item : in chars_ptr; Length : in size_t )
            return String;

with Length set to some maximum string size that I would be willing to
handle (say 20).

The trouble is that if the pointer designates a string containing 20 or
more characters before its first Nul, then, far from truncating the
result as I had expected, all Value does is raise Terminator_Error. What
is the use of that ?

Presumably I am missing something here.

Thanks for whatever help and advice you can give.

Best -- Anton Gibbs

-- 
Civil Air Traffic Management Group
Defence Evaluation and Research Agency
Bedford, UK

"The Information contained in this E-Mail and any 
subsequent correspondence is private and is intended
solely for the intended recipient(s).  For those
other than the intended recipient any disclosure,
copying, distribution, or any action taken or 
omitted to be taken in reliance on such information
is prohibited and may be unlawful."




             reply	other threads:[~1999-12-03  0:00 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
1999-12-03  0:00 Anton Gibbs [this message]
1999-12-03  0:00 ` Use of C.Strings.Value Function Considered Harmful David C. Hoos, Sr.
1999-12-06  0:00   ` Anton Gibbs
1999-12-06  0:00     ` Lutz Donnerhacke
replies disabled

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