Add FITSint() and FITSuint(),

which cast long long to int while panicking on overflow
This commit is contained in:
nhkeni
2022-03-17 18:10:38 -04:00
parent e2d5013e01
commit 7dba4f1236
9 changed files with 62 additions and 10 deletions

View File

@@ -17,6 +17,7 @@
static void xexit(int) NORETURN;
char *eos(char *); /* also used by dlb.c */
FILE *fopen_datafile(const char *, const char *);
unsigned FITSuint_(unsigned long long, const char *, int);
#ifdef DLB
#ifdef DLBLIB
@@ -543,4 +544,14 @@ xexit(int retcd)
/*NOTREACHED*/
}
/* In hacklib.c, but we don't have that and it calls panic() */
unsigned
FITSuint_(unsigned long long i, const char *file, int line){
unsigned ret = (unsigned)i;
if (ret != i) {
printf("Overflow at %s:%d\n", file, line);
xexit(EXIT_FAILURE);
}
return (unsigned)i;
}
/*dlb_main.c*/

View File

@@ -171,6 +171,8 @@ static boolean use_enum = TRUE;
extern unsigned _stklen = STKSIZ;
#endif
unsigned FITSuint_(unsigned long long, const char *, int);
/*
* Some of the routines in this source file were moved into .../src/mdlib
* to facilitate the use of a cross-compiler generation of some of the
@@ -2349,4 +2351,14 @@ struct attribs attrmax, attrmin;
#endif
#endif /* STRICT_REF_DEF */
/* In hacklib.c, but we don't have that and it calls panic() */
unsigned
FITSuint_(unsigned long long i, const char *file, int line){
unsigned ret = (unsigned)i;
if (ret != i) {
Fprintf(stdout, "Overflow at %s:%d\n", file, line);
makedefs_exit(EXIT_FAILURE);
}
return (unsigned)i;
}
/*makedefs.c*/