EPICS Controls Argonne National Laboratory

Experimental Physics and
Industrial Control System

1994  1995  1996  1997  1998  1999  2000  2001  2002  2003  2004  2005  2006  2007  2008  2009  2010  2011  <20122013  2014  2015  2016  2017  2018  2019  2020  2021  2022  2023  2024  Index 1994  1995  1996  1997  1998  1999  2000  2001  2002  2003  2004  2005  2006  2007  2008  2009  2010  2011  <20122013  2014  2015  2016  2017  2018  2019  2020  2021  2022  2023  2024 
<== Date ==> <== Thread ==>

Subject: Long string support in CA clients and device support
From: Andrew Johnson <[email protected]>
To: "EPICS tech-talk" <[email protected]>
Date: Mon, 12 Nov 2012 17:24:52 -0500
Mark Rivers has asked for clarification on how software should handle string 
termination when dealing with long strings (i.e. using DBF_CHAR arrays such as 
a waveform record to hold string data).

I recommend (but we don't require) that anything generating a long string 
should add a Nil ('\0') terminator byte after the last character and count 
that in the number of elements reported for the array (e.g. when setting the 
waveform record's NORD field).

However clients that read an array as a long string MUST be able to properly 
handle one that doesn't have a Nil terminator, and should not report an error 
in this case.  The simplest way to ensure proper termination is to check if 
the byte at [len-1] is zero and if not append one (making sure you reserved 
space in your buffer for it).

Code should always call strlen() to find the actual length of the long string 
and not rely on the array length, since there may be any number of trailing 
zero bytes included in the array data.

Clients that don't append a terminator may be protected by the recommendation 
in the second paragraph above, but not in all circumstances (for example if 
you request fewer elements than there are characters present in the string you 
will not get a terminating Nil byte, which could cause your program to crash).

Mark is modifying asynPortDriver to append the Nil bytes where possible, but 
some Asyn APIs such as asynOctet support must work with binary data as well as 
text and cannot be changed.

- Andrew
-- 
READ CAREFULLY. By reading this email, you agree, on behalf of your
employer, to release me from all obligations and waivers arising from
any and all NON-NEGOTIATED agreements, licenses, terms-of-service,
shrink-wrap, click-wrap, browse-wrap, confidentiality, non-disclosure,
non-compete and acceptable use policies ("BOGUS AGREEMENTS") that I
have entered into with your employer, its partners, licensors, agents
and assigns, in perpetuity, without prejudice to my ongoing rights
and privileges. You further represent that you have the authority to
release me from any BOGUS AGREEMENTS on behalf of your employer.

Navigate by Date:
Prev: Re: strange EPICS glitch Eric Norum
Next: Re: strange EPICS glitch Andrew Johnson
Index: 1994  1995  1996  1997  1998  1999  2000  2001  2002  2003  2004  2005  2006  2007  2008  2009  2010  2011  <20122013  2014  2015  2016  2017  2018  2019  2020  2021  2022  2023  2024 
Navigate by Thread:
Prev: Re: strange EPICS glitch Andrew Johnson
Next: RE: Long string support in CA clients and device support Mark Rivers
Index: 1994  1995  1996  1997  1998  1999  2000  2001  2002  2003  2004  2005  2006  2007  2008  2009  2010  2011  <20122013  2014  2015  2016  2017  2018  2019  2020  2021  2022  2023  2024 
ANJ, 18 Nov 2013 Valid HTML 4.01! · Home · News · About · Base · Modules · Extensions · Distributions · Download ·
· Search · EPICS V4 · IRMIS · Talk · Bugs · Documents · Links · Licensing ·