Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion ctests/test_acscte_rotateamp.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
7 changes: 0 additions & 7 deletions include/hstcal_memory.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
*/

Expand All @@ -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
Expand Down
31 changes: 17 additions & 14 deletions lib/getphttab.c
Original file line number Diff line number Diff line change
Expand Up @@ -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.

*/
Expand All @@ -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"
Comment thread
pllim marked this conversation as resolved.
Resolved

/* Internal functions to be used to interpret IMPHTTAB ref tables */
static int OpenPhotTab (char *, char *, PhtCols *);
Expand Down Expand Up @@ -288,13 +288,14 @@ 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;
int i, j, missing;
int parnum;

int PrintMissingCols_IMPHTTAB (int, int, int *, char **, char *, IRAFPointer);
int buildTabName (char *, char *, char *);

Expand All @@ -319,15 +320,16 @@ 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);
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);
}

Expand Down Expand Up @@ -394,6 +396,7 @@ static int OpenPhotTab (char *tabname, char *photvar, PhtCols *tabinfo) {
free(pncolnames);
free(pvcolnames);
free(nocol);
free(tname);

return (status);
}
Expand Down Expand Up @@ -423,7 +426,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);
Expand Down Expand Up @@ -632,7 +635,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;
Expand Down Expand Up @@ -753,15 +756,15 @@ 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
*/
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 */
Expand Down Expand Up @@ -1018,7 +1021,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;

Expand Down Expand Up @@ -1237,7 +1240,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);
Expand All @@ -1248,7 +1251,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);
Expand Down
9 changes: 1 addition & 8 deletions lib/hstcal_memory.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -70,7 +63,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)
{
Expand Down
13 changes: 11 additions & 2 deletions lib/ncarfft.f
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
32 changes: 14 additions & 18 deletions lib/trlbuf.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand Down Expand Up @@ -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))
Expand Down Expand Up @@ -629,17 +633,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);
Expand All @@ -652,7 +649,6 @@ void trlmessage(const char *fmt, ...) {
/* Send output to (temp) trailer file */
WriteTrlBuf (data);
free(data);
free(fmt_);
data = NULL;
}

Expand All @@ -661,16 +657,16 @@ 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);
}
/* 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_);
Expand All @@ -690,16 +686,16 @@ 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);
}
/* 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_);
Expand Down
Loading