From 96e8214129938577a66ae63143e9957f837ba392 Mon Sep 17 00:00:00 2001 From: "P. L. Lim" <2090236+pllim@users.noreply.github.com> Date: Thu, 1 Oct 2026 22:18:52 -0400 Subject: [PATCH 1/6] MNT: Exorcise compilation warnings from lib --- lib/getphttab.c | 22 ++++++++++++++-------- lib/hstcal_memory.c | 2 +- lib/ncarfft.f | 13 +++++++++++-- 3 files changed, 26 insertions(+), 11 deletions(-) diff --git a/lib/getphttab.c b/lib/getphttab.c index cd13ebdda..84693b681 100644 --- a/lib/getphttab.c +++ b/lib/getphttab.c @@ -16,7 +16,7 @@ MLS: 07/2015 Cleand up for unused variables and warning MLS: 08/2015 Added some initializations the clang complained about MDD: 03/2020 Ensure obs->obsmode is an empty string at the beginning of - this routine - this was a lurking bug raised in the case of + this routine - this was a lurking bug raised in the case of multiple Imsets and parameterized value. */ @@ -294,7 +294,7 @@ static int OpenPhotTab (char *tabname, char *photvar, PhtCols *tabinfo) { int *nocol; int i, j, missing; int parnum; - + int PrintMissingCols_IMPHTTAB (int, int, int *, char **, char *, IRAFPointer); int buildTabName (char *, char *, char *); @@ -319,7 +319,13 @@ static int OpenPhotTab (char *tabname, char *photvar, PhtCols *tabinfo) { } /* Create name of table with extension to be opened */ - snprintf(tname, sizeof(tname), "%s[%s]", tabname, photvar); + j = CHAR_FNAME_LENGTH - strlen(photvar) - 2 - 1; + char tabname_truncated[j]; + for (i = 0; i < (j - 1); i++) { + tabname_truncated[i] = tabname[i]; + } + tabname_truncated[j - 1] = '\0'; + snprintf(tname, sizeof(tname), "%s[%s]", tabname_truncated, photvar); /* keep track of what extension we are processing here */ strcpy(tabinfo->photvar, photvar); @@ -423,7 +429,7 @@ static int InterpretPhotmode(char *photmode, PhotPar *obs){ numpar = 0; n=0; - + /* scan entire photmode string and count how many # symbols are found */ obselems = 0; strcpy(tempmode,photmode); @@ -632,7 +638,7 @@ static int ReadPhotArray (PhtCols *tabinfo, int row, PhtRow *tabrow) { char col_parval[SZ_COLNAME]="PAR"; int nret; int n, col, i; - + n=0; col=0; i=0; @@ -753,7 +759,7 @@ static double ComputeValue(PhtRow *tabrow, PhotPar *obs) { int **bounds; /* [ndim,2] array for bounds around obsvals values */ int indx,pdim,ppos,xdim,xpos; int tabparlen; - + xdim=0; /* intermediate products used in iterating over dims @@ -1237,7 +1243,7 @@ static int PhotRowPedigree (PhotPar *obs, int row, /* Get pedigree and descrip. If either or both are missing, that's not an error in this case. */ - if (cp_pedigree > 0) { + if (cp_pedigree != NULL) { c_tbegtt (tp, cp_pedigree, row, obs->pedigree, SZ_FITS_REC); if (c_iraferr()) return (status = TABLE_ERROR); @@ -1248,7 +1254,7 @@ static int PhotRowPedigree (PhotPar *obs, int row, obs->goodPedigree = GOOD_PEDIGREE; } - if (cp_descrip > 0) { + if (cp_descrip != NULL) { c_tbegtt (tp, cp_descrip, row, obs->descrip2, SZ_FITS_REC); if (c_iraferr()) return (status = PHOTTABLE_ERROR); diff --git a/lib/hstcal_memory.c b/lib/hstcal_memory.c index 725ffed43..1a448467c 100644 --- a/lib/hstcal_memory.c +++ b/lib/hstcal_memory.c @@ -70,7 +70,7 @@ void freePtr(PtrRegister * reg, void * ptr) if (!reg || !ptr || !reg->cursor) return; - int i; + unsigned i; Bool found = False; for (i = reg->cursor; i > 0 ; --i) { diff --git a/lib/ncarfft.f b/lib/ncarfft.f index 04f33d9a9..b37f3057f 100644 --- a/lib/ncarfft.f +++ b/lib/ncarfft.f @@ -93,17 +93,26 @@ subroutine cffti1 (n,wa,xxifac) dimension rfac(15), jfac(15) equivalence (rfac(1), jfac(1)) data ntryh(1),ntryh(2),ntryh(3),ntryh(4)/3,4,2,5/ + ntry = 0 nl = n nf = 0 j = 0 101 j = j+1 - if (j-4) 102,102,103 + IF (j-4 .LE. 0) THEN + GO TO 102 + ELSE + GO TO 103 + ENDIF 102 ntry = ntryh(j) go to 104 103 ntry = ntry+2 104 nq = nl/ntry nr = nl-ntry*nq - if (nr) 101,105,101 + IF (nr .EQ. 0) THEN + GO TO 105 + ELSE + GO TO 101 + ENDIF 105 nf = nf+1 jfac(nf+2) = ntry nl = nq From 6c7db4c1f23ea507df886160a9de0d3d0ea2ca6a Mon Sep 17 00:00:00 2001 From: "P. L. Lim" <2090236+pllim@users.noreply.github.com> Date: Fri, 2 Oct 2026 14:00:42 -0400 Subject: [PATCH 2/6] Exorcise warnings in trlbuf.c --- lib/trlbuf.c | 24 ++++++++---------------- 1 file changed, 8 insertions(+), 16 deletions(-) diff --git a/lib/trlbuf.c b/lib/trlbuf.c index 336ab9a11..06eef390e 100644 --- a/lib/trlbuf.c +++ b/lib/trlbuf.c @@ -629,17 +629,10 @@ void trlmessage(const char *fmt, ...) { va_list args; va_start(args, fmt); - char *fmt_ = calloc(strlen(fmt) + 2, sizeof(*fmt_)); - if (!fmt_) { - perror("trlwarn: calloc failed"); - exit(OUT_OF_MEMORY); - } - strncpy(fmt_, fmt, strlen(fmt)); - char *data = NULL; - if (vasprintf(&data, fmt_, args) < 0) { + if (vasprintf(&data, fmt, args) < 0) { perror("trlmessage: vasprintf failed"); - fprintf(stderr, "format was: '%s'\n", fmt_); + fprintf(stderr, "format was: '%s'\n", fmt); exit(ERROR_RETURN); } va_end(args); @@ -652,7 +645,6 @@ void trlmessage(const char *fmt, ...) { /* Send output to (temp) trailer file */ WriteTrlBuf (data); free(data); - free(fmt_); data = NULL; } @@ -661,7 +653,8 @@ void trlwarn(const char *fmt, ...) { va_start(args, fmt); const char *prefix = WARN_PREFIX; - char *fmt_ = calloc(strlen(prefix) + strlen(fmt) + 1, sizeof(*fmt_)); + const unsigned n = strlen(prefix) + strlen(fmt) + 1; + char *fmt_ = calloc(n, sizeof(*fmt_)); if (!fmt_) { perror("trlwarn: calloc failed"); exit(OUT_OF_MEMORY); @@ -669,8 +662,7 @@ void trlwarn(const char *fmt, ...) { /* Create full warning message, like that output in ASNWARN */ /* Use macro to add prefix to beginning of Warning message */ char *data = NULL; - strncpy(fmt_, prefix, strlen(prefix)); - strncat(fmt_, fmt, strlen(fmt)); + snprintf(fmt_, n, "%s%s", prefix, fmt); if (vasprintf(&data, fmt_, args) < 0) { perror("trlwarn: vasprintf failed"); fprintf(stderr, "format was: '%s'\n", fmt_); @@ -690,7 +682,8 @@ void trlerror(const char *fmt, ...) { va_start(args, fmt); const char *prefix = ERR_PREFIX; - char *fmt_ = calloc(strlen(prefix) + strlen(fmt) + 1, sizeof(*fmt_)); + const unsigned n = strlen(prefix) + strlen(fmt) + 1; + char *fmt_ = calloc(n, sizeof(*fmt_)); if (!fmt_) { perror("trlerror: calloc failed"); exit(OUT_OF_MEMORY); @@ -698,8 +691,7 @@ void trlerror(const char *fmt, ...) { /* Create full error message, like that output in ASNWARN */ /* Use macro to add prefix to beginning of Warning message */ char *data = NULL; - strncpy(fmt_, prefix, strlen(prefix)); - strncat(fmt_, fmt, strlen(fmt)); + snprintf(fmt_, n, "%s%s", prefix, fmt); if (vasprintf(&data, fmt_, args) < 0) { perror("trlerror: vasprintf failed"); fprintf(stderr, "format was: '%s'\n", fmt_); From 04683b2bfd076054e560d4d443fdf845cf821c26 Mon Sep 17 00:00:00 2001 From: "P. L. Lim" <2090236+pllim@users.noreply.github.com> Date: Fri, 2 Oct 2026 14:21:59 -0400 Subject: [PATCH 3/6] Exorcise some warnings only seen on CI --- lib/getphttab.c | 4 ++-- lib/trlbuf.c | 8 ++++++-- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/lib/getphttab.c b/lib/getphttab.c index 84693b681..bc95e9624 100644 --- a/lib/getphttab.c +++ b/lib/getphttab.c @@ -767,7 +767,7 @@ static double ComputeValue(PhtRow *tabrow, PhotPar *obs) { int iter, x; int dimpow,iterpow; double *ndposd; - int b0,b1,pindx; + int b0=0,b1=0,pindx; int deltadim; /* index of varying dimension */ double bindx[2],bvals[2]; /* indices into results array for bounding values */ double rinterp; /* placeholder for interpolated result */ @@ -1024,7 +1024,7 @@ static double ComputeValue(PhtRow *tabrow, PhotPar *obs) { */ double linterp(double *x, int nx, double *fx, double xpos) { - int i0, i1; /* x values that straddle xpos */ + int i0=0, i1=0; /* x values that straddle xpos */ double value; diff --git a/lib/trlbuf.c b/lib/trlbuf.c index 06eef390e..1ad6872ce 100644 --- a/lib/trlbuf.c +++ b/lib/trlbuf.c @@ -277,7 +277,9 @@ static void CatTrlFile(FILE *ip, FILE *op) /* Now copy the file into the output trailer file */ while ( !feof(ip) ) { - fgets(buf, CHAR_LINE_LENGTH+1, ip); + if (fgets(buf, CHAR_LINE_LENGTH+1, ip) == NULL) { + break; + } fprintf(op,"%s",buf); } @@ -337,7 +339,9 @@ static int AppendTrlFile(void) while ( !feof(trlbuf.fp) ) { /* Read in a line */ - fgets(buf, CHAR_LINE_LENGTH+1, trlbuf.fp); + if (fgets(buf, CHAR_LINE_LENGTH+1, trlbuf.fp) == NULL) { + break; + } /* If we find the prefix, stop searching */ if (strstr(buf,TRL_PREFIX)) From b6186c9264ff8ac878fa72e7e696ea2ad478bb9b Mon Sep 17 00:00:00 2001 From: "P. L. Lim" <2090236+pllim@users.noreply.github.com> Date: Fri, 2 Oct 2026 14:53:00 -0400 Subject: [PATCH 4/6] Remove unused newPtrRegister because macos14 job is complaining about free-after-use --- include/hstcal_memory.h | 7 ------- lib/hstcal_memory.c | 7 ------- 2 files changed, 14 deletions(-) diff --git a/include/hstcal_memory.h b/include/hstcal_memory.h index 08c8c8bc1..c1e449969 100644 --- a/include/hstcal_memory.h +++ b/include/hstcal_memory.h @@ -22,12 +22,6 @@ * } * ... * - * Alternatively, instead of instantiating an object we can use a pointer along with the functions newPtrRegister(), - * e.g. - * - * PtrRegister * reg = newPtrRegister(); //this adds itself (this pointer) and will free itself by calling - * // freeReg() or freeOnExit() - * * NOTE: This pattern is considered integral to all use and as such internal failed allocations are asserted */ @@ -42,7 +36,6 @@ typedef struct { FreeFunction * freeFunctions; } PtrRegister; -void * newPtrRegister(); //Allocates a PtrRegister, calls initPtrRegister, registers allocated pointer then returns it void initPtrRegister(PtrRegister * reg); // initializes members, inc. alloc of registers void addPtr(PtrRegister * reg, void * ptr, void * freeFunc); // self expanding void freePtr(PtrRegister * reg, void * ptr); // non contracting diff --git a/lib/hstcal_memory.c b/lib/hstcal_memory.c index 1a448467c..b4a847f43 100644 --- a/lib/hstcal_memory.c +++ b/lib/hstcal_memory.c @@ -3,13 +3,6 @@ #include "hstio.h" #include "hstcal_memory.h" -void * newPtrRegister() -{ - void * this = malloc(sizeof(PtrRegister)); - initPtrRegister(this); - addPtr(this, this, &free); // Note: freeFunctions[0] is ignored anyhow - return this; -} void initPtrRegister(PtrRegister * reg) { reg->cursor = 0; //points to last ptr NOT next slot From f1dfa3a4d5a0c98270b0b4f3593165d3141970bc Mon Sep 17 00:00:00 2001 From: "P. L. Lim" <2090236+pllim@users.noreply.github.com> Date: Fri, 2 Oct 2026 15:33:21 -0400 Subject: [PATCH 5/6] Make Joe happy --- lib/getphttab.c | 19 ++++++++----------- 1 file changed, 8 insertions(+), 11 deletions(-) diff --git a/lib/getphttab.c b/lib/getphttab.c index bc95e9624..4a7f8c1db 100644 --- a/lib/getphttab.c +++ b/lib/getphttab.c @@ -31,7 +31,7 @@ MDD: 03/2020 Ensure obs->obsmode is an empty string at the beginning of # include "xtables.h" # include "imphttab.h" # include "c_iraf.h" /* For Bool type */ - +#include "trlbuf.h" /* Internal functions to be used to interpret IMPHTTAB ref tables */ static int OpenPhotTab (char *, char *, PhtCols *); @@ -288,7 +288,8 @@ static int OpenPhotTab (char *tabname, char *photvar, PhtCols *tabinfo) { extern int status; - char tname[CHAR_FNAME_LENGTH]; + const unsigned tname_len = strlen(tabname) + strlen(photvar) + 2 + 1; + char *tname; char **colnames, **ecolnames, **pncolnames, **pvcolnames; int *nocol; @@ -319,21 +320,16 @@ static int OpenPhotTab (char *tabname, char *photvar, PhtCols *tabinfo) { } /* Create name of table with extension to be opened */ - j = CHAR_FNAME_LENGTH - strlen(photvar) - 2 - 1; - char tabname_truncated[j]; - for (i = 0; i < (j - 1); i++) { - tabname_truncated[i] = tabname[i]; - } - tabname_truncated[j - 1] = '\0'; - snprintf(tname, sizeof(tname), "%s[%s]", tabname_truncated, photvar); + tname = calloc(tname_len, sizeof(char)); + snprintf(tname, tname_len, "%s[%s]", tabname, photvar); /* keep track of what extension we are processing here */ strcpy(tabinfo->photvar, photvar); tabinfo->tp = c_tbtopn (tname, IRAF_READ_ONLY, 0); if (c_iraferr()) { - printf ("\n==>ERROR: IMPHTTAB extension`%s' not found.\n", tname); - /*trlerror (MsgText); */ + trlerror("IMPHTTAB extension not found: %s", tname); + free(tname); return (status = OPEN_FAILED); } @@ -400,6 +396,7 @@ static int OpenPhotTab (char *tabname, char *photvar, PhtCols *tabinfo) { free(pncolnames); free(pvcolnames); free(nocol); + free(tname); return (status); } From a44d07d57d9204aba69dd6d1393bd0109897d52c Mon Sep 17 00:00:00 2001 From: "P. L. Lim" <2090236+pllim@users.noreply.github.com> Date: Thu, 5 Nov 2026 16:23:32 -0500 Subject: [PATCH 6/6] Remove null terminator from const char init --- ctests/test_acscte_rotateamp.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ctests/test_acscte_rotateamp.c b/ctests/test_acscte_rotateamp.c index 72694eaac..d3ab97e18 100644 --- a/ctests/test_acscte_rotateamp.c +++ b/ctests/test_acscte_rotateamp.c @@ -11,7 +11,7 @@ static int square_test_case_transpose(); static int square_test_case_rot(int); static int square_test_case_derot(int); -const char amps[5] = "ABCD\0"; +const char amps[5] = "ABCD"; static int setup_input_array(FloatTwoDArray *da, int nx, int ny) { int iy, ix;