From 6d7731d1f9cc28972ff4e9948f402409066d4377 Mon Sep 17 00:00:00 2001 From: David Berry Date: Mon, 6 Jun 2022 11:43:06 +0100 Subject: [PATCH] fitschan: Avoid copying overlapping input and output strings Produced an error when compiling with clang --- component.xml | 2 +- configure.ac | 2 +- src/fitschan.c | 17 ++++++++++++----- 3 files changed, 14 insertions(+), 7 deletions(-) diff --git a/component.xml b/component.xml index 66371dd9..638869e0 100644 --- a/component.xml +++ b/component.xml @@ -2,7 +2,7 @@ - 9.2.8 + 9.2.9 libext/ast WCS library diff --git a/configure.ac b/configure.ac index 436d8fdc..b73a82cd 100644 --- a/configure.ac +++ b/configure.ac @@ -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],[starlink@jiscmail.ac.uk]) AC_CONFIG_AUX_DIR([build-aux]) diff --git a/src/fitschan.c b/src/fitschan.c index 8f9e02df..386bf7e3 100644 --- a/src/fitschan.c +++ b/src/fitschan.c @@ -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-- */ @@ -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; @@ -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). */ @@ -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; }