Skip to content

Commit

Permalink
fitschan: Avoid copying overlapping input and output strings
Browse files Browse the repository at this point in the history
Produced an error when compiling with clang
  • Loading branch information
dsberry committed Jun 6, 2022
1 parent 6db0cad commit 6d7731d
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 7 deletions.
2 changes: 1 addition & 1 deletion component.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<!DOCTYPE component SYSTEM "componentinfo.dtd">

<component id="ast" support="S">
<version>9.2.8</version>
<version>9.2.9</version>
<path>libext/ast</path>
<description>WCS library</description>
<abstract>
Expand Down
2 changes: 1 addition & 1 deletion configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ dnl automake 1.6 or better.
dnl Initialisation: package name and version number
m4_define([v_maj], [9])
m4_define([v_min], [2])
m4_define([v_mic], [8])
m4_define([v_mic], [9])
m4_define([project_version], [v_maj.v_min.v_mic])
AC_INIT([ast],[project_version],[[email protected]])
AC_CONFIG_AUX_DIR([build-aux])
Expand Down
17 changes: 12 additions & 5 deletions src/fitschan.c
Original file line number Diff line number Diff line change
Expand Up @@ -1263,6 +1263,8 @@ f - AST_WRITEFITS: Write all cards out to the sink function
* 6-JAN-2022 (DSB):
* - Added attribute FitsRounding and re-wrote RoundFString.
* - Increase some buffer sizes to avoid compilation warnings.
* 6-JUN-2022 (DSB):
* Avoid copying overlapping strings in RoundFString.
*class--
*/

Expand Down Expand Up @@ -25637,8 +25639,10 @@ static void RoundFString( char *text, int width, int fitsrnd, int *status ){
char *seq9;
int bu;
int first;
int i;
int len0;
int len;
int lexp;
int nls;
int nsig;
int seqlen;
Expand All @@ -25658,8 +25662,10 @@ static void RoundFString( char *text, int width, int fitsrnd, int *status ){
*ltext = ' ';
strcpy( ltext + 1, text );

/* Locate the start of any exponent string in the local copy. */
/* Locate the start of any exponent string in the local copy. ALso get
its length. */
exp = strpbrk( ltext, "dDeE" );
lexp = exp ? strlen(exp) : 0;

/* Get a pointer to the terminator (either the exponent or the null at the end of
the string). */
Expand Down Expand Up @@ -25872,12 +25878,13 @@ static void RoundFString( char *text, int width, int fitsrnd, int *status ){
/* Loop backwards over any trailing spaces or zeros. */
while( c >= ltext && ( *c == ' ' || *c == '0' ) ) c--;

/* Ensure one space is left after a decimal point. */
if( *c == '.' ) *(++c) = '0';
/* Ensure one space is left after a decimal point, if there is room for it. */
if( *c == '.' && c < end - 1 ) *(++c) = '0';

/* Move the terminator to the following character. */
/* Move the terminator to the following character. We are sure not to
overrun the text buffer since "c" is always less than "exp". */
if( exp ) {
strcpy( c + 1, exp );
for( i = 0; i <= lexp; i++ ) c[ i + 1 ] = exp[ i ];
} else {
c[ 1 ] = 0;
}
Expand Down

0 comments on commit 6d7731d

Please sign in to comment.