Skip to content

Commit d7bcdf2

Browse files
authored
Merge pull request #85 from daneos/fix_warnings
2 parents 0189397 + b88713b commit d7bcdf2

File tree

6 files changed

+48
-36
lines changed

6 files changed

+48
-36
lines changed

asApp/src/asVerify.c

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,6 @@ int main(int argc, char **argv)
4747
{
4848
FILE *fp = NULL, *ftmp = NULL;
4949
char s[BUF_SIZE], filename[PATH_SIZE], restoreFileName[PATH_SIZE];
50-
char *tempname;
5150
int n;
5251
int numDifferences;
5352
int status;
@@ -86,28 +85,24 @@ int main(int argc, char **argv)
8685
printf("Can't open %s\n", filename);
8786
return (-1);
8887
}
89-
tempname = tmpnam(NULL);
90-
ftmp = fopen(tempname, "w");
88+
ftmp = tmpfile();
9189
if (ftmp == NULL) {
9290
printf("Can't open temp file.\n");
9391
fclose(fp);
9492
return (-1);
9593
}
96-
while (!feof(fp) && (n = fread(s, 1, BUF_SIZE, fp))) { fwrite(s, 1, n, ftmp); }
94+
while (!feof(fp) && (n = (int)fread(s, 1, BUF_SIZE, fp))) { fwrite(s, 1, n, ftmp); }
9795
fclose(fp);
9896
fp = NULL;
99-
fclose(ftmp);
100-
ftmp = NULL;
10197

10298
if (write_restore_file) {
10399
strcpy(restoreFileName, filename);
104100
strcat(restoreFileName, ".asVerify");
105101
} else {
106102
strcpy(restoreFileName, "");
107103
}
108-
numDifferences = do_asVerify(tempname, verbose, debug, write_restore_file, restoreFileName);
104+
numDifferences = do_asVerify_fp(ftmp, verbose, debug, write_restore_file, restoreFileName);
109105

110-
remove(tempname);
111106
ca_context_destroy();
112107
return (numDifferences);
113108
}

asApp/src/dbrestore.c

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,8 @@ int restoreFileListsInitialized = 0;
106106
ELLLIST pass0List;
107107
ELLLIST pass1List;
108108

109+
extern char SR_STATUS_STR[5][10];
110+
109111
void myPrintErrno(char *s, char *file, int line)
110112
{
111113
errlogPrintf("%s(%d): [0x%x]=%s:%s\n", file, line, errno, s, strerror(errno));
@@ -124,7 +126,7 @@ float mySafeDoubleToFloat(double d)
124126
if (d > 0.0) f = FLT_MIN;
125127
else f = -FLT_MIN;
126128
} else {
127-
f = d;
129+
f = (float)d;
128130
}
129131
return (f);
130132
}
@@ -290,7 +292,7 @@ STATIC long scalar_restore(int pass, DBENTRY *pdbentry, char *PVname, char *valu
290292
status = dbNameToAddr(PVname, paddr);
291293
if (!status) {
292294
if (is_long_string && paddr->field_type == DBF_CHAR) {
293-
status = dbPut(paddr, DBF_CHAR, value_string, strlen(value_string) + 1);
295+
status = dbPut(paddr, DBF_CHAR, value_string, (long)strlen(value_string) + 1);
294296
} else {
295297
status = dbPut(paddr, DBF_STRING, value_string, 1);
296298
}
@@ -397,11 +399,15 @@ long SR_array_restore(int pass, FILE *inp_fd, char *PVname, char *value_string,
397399
char *p_char = NULL;
398400
short *p_short = NULL;
399401
epicsInt32 *p_long = NULL;
402+
#ifdef DBR_INT64
400403
epicsInt64 *p_int64 = NULL;
404+
#endif
401405
unsigned char *p_uchar = NULL;
402406
unsigned short *p_ushort = NULL;
403407
epicsUInt32 *p_ulong = NULL;
408+
#ifdef DBR_INT64
404409
epicsUInt64 *p_uint64 = NULL;
410+
#endif
405411
float *p_float = NULL;
406412
double *p_double = NULL;
407413

@@ -942,8 +948,10 @@ int reboot_restore(char *filename, initHookState init_state)
942948
printf(" ebuffer='%s'\n", ebuffer);
943949
}
944950
}
945-
n = BUF_SIZE - strlen(value_string) - 1;
951+
n = BUF_SIZE - (int)strlen(value_string) - 1;
946952
strncat(value_string, bp, n);
953+
/* make sure value_string is properly null-terminated */
954+
value_string[BUF_SIZE - 1] = '\0';
947955
/* we don't want that '\n' in the string */
948956
if (value_string[strlen(value_string) - 1] == '\n') value_string[strlen(value_string) - 1] = '\0';
949957
}
@@ -1501,7 +1509,7 @@ void makeAutosaveFileFromDbInfo(char *fileBaseName, char *info_name)
15011509
for (pend = pbegin; *pend && !isspace((int)*pend); pend++) {}
15021510
/* pend points to whitespace or \0 */
15031511

1504-
flen = pend - pbegin;
1512+
flen = (int)(pend - pbegin);
15051513
if (flen >= sizeof(field) - 1) flen = sizeof(field) - 1;
15061514
memcpy(field, pbegin, flen);
15071515
field[flen] = '\0';

asApp/src/os/WIN32/osdNfs.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515

1616
/* definition except for vxWorks */
1717
#define OK 0
18+
#undef ERROR /* ERROR is defined by Windows in wingdi.h */
1819
#define ERROR -1
1920
#define logMsg errlogPrintf
2021

asApp/src/save_restore.c

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -179,6 +179,7 @@
179179
#define SET_FILE_PERMISSIONS 1
180180

181181
#ifdef _WIN32
182+
#undef SET_FILE_PERMISSIONS
182183
#define SET_FILE_PERMISSIONS 0
183184
#endif
184185

@@ -343,6 +344,9 @@ STATIC epicsThreadId taskID = 0; /* save_restore task ID */
343344
/*** stuff for reporting status to EPICS client ***/
344345
STATIC char status_prefix[30] = "";
345346

347+
/* Make sure to leave room for trailing null */
348+
char SR_STATUS_STR[5][10] = {"No Status", " Failure ", " Warning ", " Warning ", " Ok "};
349+
346350
STATIC long SR_status = SR_STATUS_INIT;
347351
STATIC unsigned short SR_heartbeat = 0;
348352
STATIC char SR_statusStr[STATUS_STR_LEN] = "", SR_recentlyStr[STATUS_STR_LEN] = "";
@@ -599,7 +603,7 @@ STATIC void on_change_timer(CALLBACK *pcallback)
599603
STATIC void on_change_save(struct event_handler_args event)
600604
{
601605
struct chlist *plist;
602-
if (save_restoreDebug >= 10) { logMsg("on_change_save: event.usr=0x%lx\n", (unsigned long)event.usr); }
606+
if (save_restoreDebug >= 10) { logMsg("on_change_save: event.usr=0x%llx\n", (unsigned long long)event.usr); }
603607
plist = (struct chlist *)event.usr;
604608

605609
if (plist) {
@@ -2373,7 +2377,7 @@ STATIC int create_data_set(char *filename, /* save set request file
23732377
while ((plist->save_file[inx] != 0) && (plist->save_file[inx] != '.') && (inx < (FN_LEN-6))) inx++;
23742378
#else
23752379
/* fix bfr 2007-10-01: need to search for last '.', not first */
2376-
inx = strlen(plist->save_file) - 1;
2380+
inx = (int)strlen(plist->save_file) - 1;
23772381
while (inx > 0 && plist->save_file[inx] != '.') inx--;
23782382
#endif
23792383
plist->save_file[inx] = 0; /* truncate if necessary to leave room for ".sav" + null */
@@ -2513,8 +2517,8 @@ int set_requestfile_path(char *path, char *pathsub)
25132517
char fullpath[MAX_PATH_LEN + 1] = "";
25142518
int path_len = 0, pathsub_len = 0;
25152519

2516-
if (path && *path) path_len = strlen(path);
2517-
if (pathsub && *pathsub) pathsub_len = strlen(pathsub);
2520+
if (path && *path) path_len = (int)strlen(path);
2521+
if (pathsub && *pathsub) pathsub_len = (int)strlen(pathsub);
25182522
if (path_len + pathsub_len > (MAX_PATH_LEN - 1)) { /* may have to add '/' */
25192523
ERRLOG("'path'+'pathsub' is too long\n");
25202524
return (ERROR);
@@ -3305,7 +3309,7 @@ STATIC int do_manual_restore(char *filename, int file_type, char *macrostring)
33053309
if (bp[strlen(bp) - 1] != '\n') {
33063310
/* No, we didn't. One more read will certainly accumulate a value string of length BUF_SIZE */
33073311
bp = fgets(buffer, BUF_SIZE, inp_fd);
3308-
n = BUF_SIZE - strlen(value_string) - 1;
3312+
n = BUF_SIZE - (int)strlen(value_string) - 1;
33093313
strncat(value_string, bp, n);
33103314
if (value_string[strlen(value_string) - 1] == '\n')
33113315
value_string[strlen(value_string) - 1] = '\0';
@@ -3319,7 +3323,7 @@ STATIC int do_manual_restore(char *filename, int file_type, char *macrostring)
33193323
} else if (ca_pend_io(0.5) != ECA_NORMAL) {
33203324
num_errs++;
33213325
/* Don't forget trailing null character: "strlen(value_string)+1" below */
3322-
} else if (ca_array_put(DBR_CHAR, strlen(value_string) + 1, chanid, value_string) != ECA_NORMAL) {
3326+
} else if (ca_array_put(DBR_CHAR, (unsigned long)strlen(value_string) + 1, chanid, value_string) != ECA_NORMAL) {
33233327
printf("save_restore:do_manual_restore: ca_array_put of '%s' to '%s' failed\n", value_string,
33243328
PVname);
33253329
num_errs++;

asApp/src/save_restore.h

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,6 @@
2929
#define MAX(a, b) ((a) > (b) ? (a) : (b))
3030
#define MIN(a, b) ((a) < (b) ? (a) : (b))
3131

32-
/* Make sure to leave room for trailing null */
33-
static char SR_STATUS_STR[5][10] = {"No Status", " Failure ", " Warning ", " Warning ", " Ok "};
34-
3532
#define SR_STATUS_OK 4
3633
#define SR_STATUS_SEQ_WARN 3
3734
#define SR_STATUS_WARN 2
@@ -90,6 +87,7 @@ extern struct restoreList restoreFileList;
9087
extern int myFileCopy(const char *source, const char *dest);
9188
extern void dbrestoreShow(void);
9289
extern int do_asVerify(char *fileName, int verbose, int debug, int write_restore_file, char *restoreFileName);
90+
extern int do_asVerify_fp(FILE *fp, int verbose, int debug, int write_restore_file, char *restoreFileName);
9391

9492
extern volatile int save_restoreRemountThreshold;
9593

asApp/src/verify.c

Lines changed: 21 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -35,16 +35,28 @@
3535

3636
long read_array(FILE *fp, char *PVname, char *value_string, short field_type, long element_count, char *read_buffer,
3737
int debug);
38+
int do_asVerify_fp(FILE *fp, int verbose, int debug, int write_restore_file, char *restoreFileName);
3839

3940
/* verbose==-1 means don't say anything unless there's a problem. */
4041
int do_asVerify(char *fileName, int verbose, int debug, int write_restore_file, char *restoreFileName)
42+
{
43+
FILE *fp = NULL;
44+
fp = fopen(fileName, "r");
45+
if (fp == NULL) {
46+
printf("asVerify: Can't open '%s'.\n", fileName);
47+
return (-1);
48+
}
49+
return do_asVerify_fp(fp, verbose, debug, write_restore_file, restoreFileName);
50+
}
51+
52+
int do_asVerify_fp(FILE *fp, int verbose, int debug, int write_restore_file, char *restoreFileName)
4153
{
4254
float *pfvalue, *pf_read;
4355
double *pdvalue, *pd_read, diff, max_diff = 0.;
4456
short *penum_value, *penum_value_read;
4557
char *svalue, *svalue_read;
4658
chid chid;
47-
FILE *fp = NULL, *fr = NULL, *fr1 = NULL;
59+
FILE *fr = NULL, *fr1 = NULL;
4860
char c, s[BUF_SIZE], *bp, PVname[PV_NAME_LEN + 1], value_string[BUF_SIZE];
4961
char trial_restoreFileName[PATH_SIZE];
5062
char *CA_buffer = NULL, *read_buffer = NULL, *pc = NULL;
@@ -54,12 +66,6 @@ int do_asVerify(char *fileName, int verbose, int debug, int write_restore_file,
5466
int different, wrote_head = 0, status, file_ok = 0;
5567
long element_count = 0, storageBytes = 0, alloc_CA_buffer = 0;
5668

57-
fp = fopen(fileName, "r");
58-
if (fp == NULL) {
59-
printf("asVerify: Can't open '%s'.\n", fileName);
60-
return (-1);
61-
}
62-
6369
if (write_restore_file) {
6470
strcpy(trial_restoreFileName, restoreFileName);
6571
strcat(trial_restoreFileName, "B");
@@ -74,11 +80,11 @@ int do_asVerify(char *fileName, int verbose, int debug, int write_restore_file,
7480
}
7581
/* check that (copy of) .sav file is good */
7682
status = fseek(fp, -6, SEEK_END);
77-
fgets(s, 6, fp);
83+
if (fgets(s, 6, fp) == NULL) file_ok = 0;
7884
if (strncmp(s, "<END>", 5) == 0) file_ok = 1;
7985
if (!file_ok) {
8086
status = fseek(fp, -7, SEEK_END);
81-
fgets(s, 7, fp);
87+
if (fgets(s, 7, fp) == NULL) file_ok = 0;
8288
if (strncmp(s, "<END>", 5) == 0) file_ok = 1;
8389
}
8490
if (status || !file_ok) {
@@ -328,13 +334,13 @@ int do_asVerify(char *fileName, int verbose, int debug, int write_restore_file,
328334
/* No, we didn't. One more read will certainly accumulate a value string of length BUF_SIZE */
329335
if (debug > 3) printf("did not reach end of line for long-string PV\n");
330336
bp = fgets(s, BUF_SIZE, fp);
331-
n = BUF_SIZE - strlen(value_string) - 1;
337+
n = BUF_SIZE - (int)strlen(value_string) - 1;
332338
strncat(value_string, bp, n);
333339
if (value_string[strlen(value_string) - 1] == '\n')
334340
value_string[strlen(value_string) - 1] = '\0';
335341
}
336342
/* Discard additional characters until end of line */
337-
while (bp[strlen(bp) - 1] != '\n') fgets(s, BUF_SIZE, fp);
343+
while (bp[strlen(bp) - 1] != '\n' && fgets(s, BUF_SIZE, fp) != NULL);
338344

339345
status = ca_array_get(DBR_CHAR, element_count, chid, (void *)svalue);
340346
} else {
@@ -370,7 +376,7 @@ int do_asVerify(char *fileName, int verbose, int debug, int write_restore_file,
370376
if (different || (verbose > 0)) {
371377
WRITE_HEADER;
372378
if (is_scalar || is_long_string) {
373-
nspace = 24 - strlen(value_string);
379+
nspace = 24 - (int)strlen(value_string);
374380
if (nspace < 1) nspace = 1;
375381
printf("%s%-24s '%s'%*s'%s'\n", different ? "*** " : " ", PVname, value_string,
376382
nspace, "", svalue);
@@ -455,7 +461,7 @@ static float safeDoubleToFloat(double d)
455461
if (d > 0.0) f = FLT_MIN;
456462
else f = -FLT_MIN;
457463
} else {
458-
f = d;
464+
f = (float)d;
459465
}
460466
return (f);
461467
}
@@ -536,7 +542,7 @@ long read_array(FILE *fp, char *PVname, char *value_string, short field_type, lo
536542
* If there are more characters than we can handle, just pretend we read them.
537543
*/
538544
/* *bp == ELEMENT_END ,*/
539-
if (debug > 1) printf("array_read: looking for element-end: '%s'\n", bp);
545+
if (debug > 1) printf("array_read: looking for element-end: '%s'\n", bp ? bp : "(null)");
540546
for (found = 0; (found == 0) && !end_of_file;) {
541547
while (*bp && (*bp != ELEMENT_END) && (*bp != ESCAPE)) bp++;
542548
switch (*bp) {
@@ -613,7 +619,7 @@ long read_array(FILE *fp, char *PVname, char *value_string, short field_type, lo
613619
if ((bp = fgets(buffer, BUF_SIZE, fp)) == NULL) end_of_file = 1;
614620
}
615621
}
616-
if (debug > 1) printf("array_read: positioned for next PV '%s'\n", bp);
622+
if (debug > 1) printf("array_read: positioned for next PV '%s'\n", bp ? bp : "(null)");
617623
if (!status && end_of_file) status = end_of_file;
618624

619625
return (status);

0 commit comments

Comments
 (0)