Skip to content
Snippets Groups Projects
Commit 28a7c47c authored by deuce's avatar deuce
Browse files

Clean up the help functions per Coverity by checking the return values of

f*().
parent 78468dd3
No related branches found
No related tags found
No related merge requests found
...@@ -2702,13 +2702,10 @@ static void help(void) ...@@ -2702,13 +2702,10 @@ static void help(void)
_setcursortype(_NOCURSOR); _setcursortype(_NOCURSOR);
if(api->helpbuf!=NULL) if(!api->helpbuf) {
strcpy(hbuf,api->helpbuf); if((fp=fopen(api->helpixbfile,"rb"))==NULL)
else { sprintf(hbuf,"ERROR: Cannot open help index: %s"
if((fp=fopen(api->helpixbfile,"rb"))==NULL) {
sprintf(hbuf,"\2 ERROR \2 Cannot open help index:\r\n %s"
,api->helpixbfile); ,api->helpixbfile);
}
else { else {
p=strrchr(helpfile,'/'); p=strrchr(helpfile,'/');
if(p==NULL) if(p==NULL)
...@@ -2719,33 +2716,45 @@ static void help(void) ...@@ -2719,33 +2716,45 @@ static void help(void)
p++; p++;
l=-1L; l=-1L;
while(!feof(fp)) { while(!feof(fp)) {
if(!fread(str,12,1,fp)) if(fread(str,12,1,fp)!=1)
break; break;
str[12]=0; str[12]=0;
fread(&line,sizeof(line),1,fp); if(fread(&line,2,1,fp)!=1);
if(stricmp(str,p) || line!=helpline) { if(stricmp(str,p) || line!=helpline) {
fseek(fp,sizeof(l),SEEK_CUR); if(fseek(fp,4,SEEK_CUR)==0)
break;
continue; continue;
} }
fread(&l,sizeof(l),1,fp); if(fread(&l,4,1,fp)!=1)
l=-1L;
break; break;
} }
fclose(fp); fclose(fp);
if(l==-1L) if(l==-1L)
sprintf(hbuf,"\2 ERROR \2 Cannot locate help key (%s:%u) in:\r\n" sprintf(hbuf,"ERROR: Cannot locate help key (%s:%u) in: %s"
" %s",p,helpline,api->helpixbfile); ,p,helpline,api->helpixbfile);
else { else {
if((fp=fopen(api->helpdatfile,"rb"))==NULL) if((fp=fopen(api->helpdatfile,"rb"))==NULL)
sprintf(hbuf,"\2 ERROR \2 Cannot open help file:\r\n %s" sprintf(hbuf,"ERROR: Cannot open help file: %s"
,api->helpdatfile); ,api->helpdatfile);
else { else {
fseek(fp,l,SEEK_SET); if(fseek(fp,l,SEEK_SET)!=0) {
fread(hbuf,HELPBUF_SIZE,1,fp); sprintf(hbuf,"ERROR: Cannot seek to help key (%s:%u) at %ld in: %s"
fclose(fp); ,p,helpline,l,api->helpixbfile);
} }
else {
if(fread(hbuf,1,HELPBUF_SIZE,fp)<1) {
sprintf(hbuf,"ERROR: Cannot read help key (%s:%u) at %ld in: %s"
,p,helpline,l,api->helpixbfile);
}
}
fclose(fp);
} }
} }
} }
showbuf(WIN_MID|WIN_HLP, 0, 0, 76, api->scrn_len, "Online Help", hbuf, NULL, NULL); showbuf(WIN_MID|WIN_HLP, 0, 0, 76, api->scrn_len, "Online Help", hbuf, NULL, NULL);
} }
else {
showbuf(WIN_MID|WIN_HLP, 0, 0, 76, api->scrn_len, "Online Help", api->helpbuf, NULL, NULL);
}
}
...@@ -411,15 +411,19 @@ void help() ...@@ -411,15 +411,19 @@ void help()
p++; p++;
l=-1L; l=-1L;
while(!feof(fp)) { while(!feof(fp)) {
if(!fread(str,12,1,fp)) if(fread(str,12,1,fp)!=1)
break; break;
str[12]=0; str[12]=0;
fread(&line,2,1,fp); if(fread(&line,2,1,fp)!=1);
if(stricmp(str,p) || line!=helpline) { if(stricmp(str,p) || line!=helpline) {
fseek(fp,4,SEEK_CUR); if(fseek(fp,4,SEEK_CUR)==0)
continue; } break;
fread(&l,4,1,fp); continue;
break; } }
if(fread(&l,4,1,fp)!=1)
l=-1L;
break;
}
fclose(fp); fclose(fp);
if(l==-1L) if(l==-1L)
sprintf(hbuf,"ERROR: Cannot locate help key (%s:%u) in: %s" sprintf(hbuf,"ERROR: Cannot locate help key (%s:%u) in: %s"
...@@ -429,21 +433,31 @@ void help() ...@@ -429,21 +433,31 @@ void help()
sprintf(hbuf,"ERROR: Cannot open help file: %s" sprintf(hbuf,"ERROR: Cannot open help file: %s"
,api->helpdatfile); ,api->helpdatfile);
else { else {
fseek(fp,l,SEEK_SET); if(fseek(fp,l,SEEK_SET)!=0) {
fread(hbuf,HELPBUF_SIZE,1,fp); sprintf(hbuf,"ERROR: Cannot seek to help key (%s:%u) at %ld in: %s"
fclose(fp); ,p,helpline,l,api->helpixbfile);
} }
else {
if(fread(hbuf,1,HELPBUF_SIZE,fp)<1) {
sprintf(hbuf,"ERROR: Cannot read help key (%s:%u) at %ld in: %s"
,p,helpline,l,api->helpixbfile);
}
}
fclose(fp);
} }
} }
} }
else
strcpy(hbuf,api->helpbuf);
uputs(hbuf); uputs(hbuf);
if(strlen(hbuf)>200) { if(strlen(hbuf)>200) {
printf("Hit enter"); printf("Hit enter");
getstr(str,sizeof(str)-1); getstr(str,sizeof(str)-1);
} }
} }
else {
uputs(api->helpbuf);
if(strlen(api->helpbuf)>200) {
printf("Hit enter");
getstr(str,sizeof(str)-1);
}
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment