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=-1.3 required=5.0 tests=BAYES_00,INVALID_MSGID autolearn=no autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,b41415bcc9748556,start X-Google-Attributes: gid103376,public From: Anton Gibbs Subject: Use of C.Strings.Value Function Considered Harmful Date: 1999/12/03 Message-ID: <3847E5CE.4F9E@dera.gov.uk>#1/1 X-Deja-AN: 556238964 Content-Transfer-Encoding: 7bit Organization: Eurocontrol Integration Team Content-Type: text/plain; charset=us-ascii Mime-Version: 1.0 Newsgroups: comp.lang.ada Date: 1999-12-03T00:00:00+00:00 List-Id: 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."