From 6201d377561c3230ca68e6e9871db8e2912644d2 Mon Sep 17 00:00:00 2001 From: Eric Norum Date: Fri, 14 Dec 2018 11:38:31 -0600 Subject: [PATCH 1/4] Remove epicsTempName() routine It's unsafe and generates obnoxious warnings on modern compilers. This also replaces internal useage with epicsTempFile(). There appears to be no external code that calls this routine. --- src/libCom/flex/flex.c | 14 ++---- src/libCom/flex/flexdef.h | 2 - src/libCom/flex/gen.c | 9 +--- src/libCom/misc/truncateFile.c | 61 +++++++++++------------ src/libCom/osi/epicsTempFile.h | 1 - src/libCom/osi/os/WIN32/epicsTempFile.cpp | 22 -------- src/libCom/osi/os/posix/epicsTempFile.cpp | 14 ------ 7 files changed, 35 insertions(+), 88 deletions(-) diff --git a/src/libCom/flex/flex.c b/src/libCom/flex/flex.c index 8d0400c2b..008e5e670 100644 --- a/src/libCom/flex/flex.c +++ b/src/libCom/flex/flex.c @@ -98,7 +98,6 @@ int num_backtracking, bol_needed; FILE *temp_action_file; FILE *backtrack_file; int end_of_buffer_state; -char action_file_name[256>L_tmpnam?256:L_tmpnam]; char **input_files; int num_input_files; char *program_name; @@ -210,10 +209,7 @@ void flexend(int status) else if ( fclose( temp_action_file ) ) flexfatal( "error occurred when closing temporary action file" ); - - else if ( unlink( action_file_name ) ) - flexfatal( "error occurred when deleting temporary action file" ); - } + } if ( status != 0 && outfile_created ) { @@ -598,15 +594,11 @@ get_next_arg: /* used by -C and -S flags in lieu of a "continue 2" control */ if ( (skelfile = fopen( skelname, "r" )) == NULL ) lerrsf( "can't open skeleton file %s", skelname ); - epicsTempName ( action_file_name, sizeof ( action_file_name ) ); - if ( action_file_name[0] == '\0' ) + if ( ( temp_action_file = epicsTempFile () ) == NULL ) { - lerrsf( "can't create temporary file name", "" ); + lerrsf( "can't create temporary action file", "" ); } - if ( ( temp_action_file = fopen ( action_file_name, "w" ) ) == NULL ) - lerrsf( "can't open temporary action file %s", action_file_name ); - lastdfa = lastnfa = num_rules = numas = numsnpairs = tmpuses = 0; numecs = numeps = eps2 = num_reallocs = hshcol = dfaeql = totnst = 0; numuniq = numdup = hshsave = eofseen = datapos = dataline = 0; diff --git a/src/libCom/flex/flexdef.h b/src/libCom/flex/flexdef.h index 79cfa9427..cf972b274 100644 --- a/src/libCom/flex/flexdef.h +++ b/src/libCom/flex/flexdef.h @@ -350,7 +350,6 @@ extern int yymore_really_used, reject_really_used; * temp_action_file - temporary file to hold actions * backtrack_file - file to summarize backtracking states to * infilename - name of input file - * action_file_name - name of the temporary file * input_files - array holding names of input files * num_input_files - size of input_files array * program_name - name with which program was invoked @@ -359,7 +358,6 @@ extern int yymore_really_used, reject_really_used; extern int datapos, dataline, linenum; extern FILE *skelfile, *yyin, *temp_action_file, *backtrack_file; extern char *infilename; -extern char action_file_name[]; extern char **input_files; extern int num_input_files; extern char *program_name; diff --git a/src/libCom/flex/gen.c b/src/libCom/flex/gen.c index aad884074..d0219ec94 100644 --- a/src/libCom/flex/gen.c +++ b/src/libCom/flex/gen.c @@ -1164,13 +1164,8 @@ void make_tables(void) if ( ferror( temp_action_file ) ) flexfatal( "error occurred when writing temporary action file" ); - else if ( fclose( temp_action_file ) ) - flexfatal( "error occurred when closing temporary action file" ); - - temp_action_file = fopen( action_file_name, "r" ); - - if ( temp_action_file == NULL ) - flexfatal( "could not re-open temporary action file" ); + else if ( fseek( temp_action_file, 0L, SEEK_SET) != 0 ) + flexfatal( "error occurred when rewinding temporary action file" ); /* copy prolog from action_file to output file */ action_out(); diff --git a/src/libCom/misc/truncateFile.c b/src/libCom/misc/truncateFile.c index ccb1450c2..4fd83075f 100644 --- a/src/libCom/misc/truncateFile.c +++ b/src/libCom/misc/truncateFile.c @@ -27,7 +27,6 @@ */ epicsShareFunc enum TF_RETURN truncateFile (const char *pFileName, unsigned long size) { - char tmpName[256>L_tmpnam?256:L_tmpnam]; long filePos; FILE *pFile; FILE *ptmp; @@ -67,18 +66,10 @@ epicsShareFunc enum TF_RETURN truncateFile (const char *pFileName, unsigned lon return TF_OK; } - epicsTempName ( tmpName, sizeof (tmpName) ); - if ( tmpName[0] == '\0' ) { - fprintf (stderr,"Unable to create tmp file name?\n"); - fclose (pFile); - return TF_ERROR; - } - - ptmp = fopen (tmpName, "w"); + ptmp = epicsTempFile(); if (!ptmp) { fprintf (stderr, - "File access problems to `%s' because `%s'\n", - tmpName, + "File access problems to temp file because `%s'\n", strerror(errno)); fclose (pFile); return TF_ERROR; @@ -89,48 +80,56 @@ epicsShareFunc enum TF_RETURN truncateFile (const char *pFileName, unsigned lon c = getc (pFile); if (c==EOF) { fprintf (stderr, - "File access problems to `%s' because `%s'\n", - pFileName, + "File access problems to temp file because `%s'\n", strerror(errno)); fclose (pFile); fclose (ptmp); - remove (tmpName); return TF_ERROR; } status = putc (c, ptmp); if (status==EOF) { fprintf(stderr, - "File access problems to `%s' because `%s'\n", - tmpName, + "File access problems to temp file because `%s'\n", strerror(errno)); fclose (pFile); fclose (ptmp); - remove (tmpName); return TF_ERROR; } charNo++; } fclose (pFile); - fclose (ptmp); - status = remove (pFileName); - if (status!=TF_OK) { + pFile = fopen(pFileName, "w"); + if (!pFile) { fprintf (stderr, - "Unable to remove `%s' during truncate because `%s'\n", + "File access problems to `%s' because `%s'\n", pFileName, strerror(errno)); - remove (tmpName); + fclose (ptmp); return TF_ERROR; } - status = rename (tmpName, pFileName); - if (status!=TF_OK) { - fprintf (stderr, - "Unable to rename %s to `%s' because `%s'\n", - tmpName, - pFileName, - strerror(errno)); - remove (tmpName); - return TF_ERROR; + rewind (ptmp); + while ((c = getc (ptmp)) != EOF) { + if (ferror(ptmp)) { + fprintf (stderr, + "File access problems to temp file because `%s'\n", + strerror(errno)); + fclose (pFile); + fclose (ptmp); + return TF_ERROR; + } + status = putc (c, pFile); + if (status==EOF) { + fprintf(stderr, + "File access problems to `%s' because `%s'\n", + pFileName, + strerror(errno)); + fclose (pFile); + fclose (ptmp); + return TF_ERROR; + } } + fclose(ptmp); + fclose(pFile); return TF_OK; } diff --git a/src/libCom/osi/epicsTempFile.h b/src/libCom/osi/epicsTempFile.h index c48e336ec..e20879d04 100644 --- a/src/libCom/osi/epicsTempFile.h +++ b/src/libCom/osi/epicsTempFile.h @@ -20,7 +20,6 @@ extern "C" { #endif -epicsShareFunc void epicsShareAPI epicsTempName(char *pbuf, size_t bufLen); epicsShareFunc FILE * epicsShareAPI epicsTempFile(void); #ifdef __cplusplus diff --git a/src/libCom/osi/os/WIN32/epicsTempFile.cpp b/src/libCom/osi/os/WIN32/epicsTempFile.cpp index 11b835134..2283a8574 100644 --- a/src/libCom/osi/os/WIN32/epicsTempFile.cpp +++ b/src/libCom/osi/os/WIN32/epicsTempFile.cpp @@ -21,28 +21,6 @@ #define epicsExportSharedSymbols #include "epicsTempFile.h" -// -// epicsTempName -// -// allow the teporary file directory to be set with the -// TMP environment varianble -// -extern "C" -epicsShareFunc void epicsShareAPI epicsTempName ( - char * pNameBuf, size_t nameBufLength ) -{ - if ( nameBufLength ) { - pNameBuf[0] = '\0'; - char * pName = _tempnam ( "c:\\tmp", "epics" ); - if ( pName ) { - if ( nameBufLength > strlen ( pName ) ) { - strncpy ( pNameBuf, pName, nameBufLength ); - } - free ( pName ); - } - } -} - // // epicsTmpFile // diff --git a/src/libCom/osi/os/posix/epicsTempFile.cpp b/src/libCom/osi/os/posix/epicsTempFile.cpp index 19b5fb4bc..8e666b4b6 100644 --- a/src/libCom/osi/os/posix/epicsTempFile.cpp +++ b/src/libCom/osi/os/posix/epicsTempFile.cpp @@ -14,20 +14,6 @@ #include "epicsTempFile.h" extern "C" -epicsShareFunc void epicsShareAPI epicsTempName ( - char * pNameBuf, size_t nameBufLength ) -{ - if ( nameBufLength ) { - pNameBuf[0] = '\0'; - char nameBuf[L_tmpnam]; - if ( tmpnam ( nameBuf ) ) { - if ( nameBufLength > strlen ( nameBuf ) ) { - strncpy ( pNameBuf, nameBuf, nameBufLength ); - } - } - } -} - extern "C" epicsShareFunc FILE * epicsShareAPI epicsTempFile ( void ) From a5aa5459e3a3d57950aefe3fdb20719308cdbfa7 Mon Sep 17 00:00:00 2001 From: Eric Norum Date: Fri, 14 Dec 2018 15:30:28 -0600 Subject: [PATCH 2/4] Drop extraneous extern "C" --- src/libCom/osi/os/posix/epicsTempFile.cpp | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/libCom/osi/os/posix/epicsTempFile.cpp b/src/libCom/osi/os/posix/epicsTempFile.cpp index 8e666b4b6..c015f0418 100644 --- a/src/libCom/osi/os/posix/epicsTempFile.cpp +++ b/src/libCom/osi/os/posix/epicsTempFile.cpp @@ -13,8 +13,6 @@ #define epicsExportSharedSymbols #include "epicsTempFile.h" -extern "C" - extern "C" epicsShareFunc FILE * epicsShareAPI epicsTempFile ( void ) { From d41355e0fc2c48f2bcb7d86d32f4de0f5768e97a Mon Sep 17 00:00:00 2001 From: Eric Norum Date: Fri, 14 Dec 2018 15:38:10 -0600 Subject: [PATCH 3/4] Add error checking to the copy-back loop in truncateFile() --- src/libCom/misc/truncateFile.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/libCom/misc/truncateFile.c b/src/libCom/misc/truncateFile.c index 4fd83075f..dc074d9fb 100644 --- a/src/libCom/misc/truncateFile.c +++ b/src/libCom/misc/truncateFile.c @@ -108,8 +108,10 @@ epicsShareFunc enum TF_RETURN truncateFile (const char *pFileName, unsigned lon return TF_ERROR; } rewind (ptmp); - while ((c = getc (ptmp)) != EOF) { - if (ferror(ptmp)) { + charNo = 0u; + while (charNo Date: Fri, 14 Dec 2018 16:58:43 -0600 Subject: [PATCH 4/4] Release notes updated --- documentation/RELEASE_NOTES.html | 30 ++++++++++++++++++++++++++++-- 1 file changed, 28 insertions(+), 2 deletions(-) diff --git a/documentation/RELEASE_NOTES.html b/documentation/RELEASE_NOTES.html index d477ca3bd..4e317c84d 100644 --- a/documentation/RELEASE_NOTES.html +++ b/documentation/RELEASE_NOTES.html @@ -16,10 +16,36 @@ -

Changes from the 3.14 branch since 3.15.6

+

Routine epicsTempName() removed from libCom

- +

This routine was a simple wrapper around the C89 function tmpnam() +which is now seen as unsafe and causes warning messages to be generated by +most modern compilers. The two internal uses of this function have been +modified to call epicsTempFile() instead. We were unable to find any +published code that used this function, so it was removed immediately instead +of being deprecated.

+

DBD Parsing of Record Types

+ +

The Perl DBD file parser has been made slightly more liberal; the order in +which DBD files must be parsed is now more flexible, so that a record type +definition can now be parsed after a device support that referred to that +record type. A warning message will be displayed when the device support is +seen, but the subsequent loading of the record type will be accepted without +triggering an error. See +Launchpad bug +#1801145.

+ +

menuScan and several record types documented with POD

+ +

The EPICS Wiki pages describing a number of standard record types has been +converted into the Perl POD documentation format and added to the DBD files, +so at build-time an HTML version of these documents is generated and installed +into the htmls directory. Thanks to Tony Pietryla.

+ +

CA client tools learned -V option

+ +

This displays the version numbers of EPICS Base and the CA protocol.

Changes made between 3.15.5 and 3.15.6