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
...@@ -2702,50 +2702,59 @@ static void help(void) ...@@ -2702,50 +2702,59 @@ 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) { ,api->helpixbfile);
sprintf(hbuf,"\2 ERROR \2 Cannot open help index:\r\n %s" else {
,api->helpixbfile); p=strrchr(helpfile,'/');
} if(p==NULL)
else { p=strrchr(helpfile,'\\');
p=strrchr(helpfile,'/'); if(p==NULL)
if(p==NULL) p=helpfile;
p=strrchr(helpfile,'\\'); else
if(p==NULL) p++;
p=helpfile; l=-1L;
else while(!feof(fp)) {
p++; if(fread(str,12,1,fp)!=1)
l=-1L; break;
while(!feof(fp)) { str[12]=0;
if(!fread(str,12,1,fp)) if(fread(&line,2,1,fp)!=1);
break; if(stricmp(str,p) || line!=helpline) {
str[12]=0; if(fseek(fp,4,SEEK_CUR)==0)
fread(&line,sizeof(line),1,fp); break;
if(stricmp(str,p) || line!=helpline) { continue;
fseek(fp,sizeof(l),SEEK_CUR); }
continue; if(fread(&l,4,1,fp)!=1)
} l=-1L;
fread(&l,sizeof(l),1,fp); break;
break; }
} fclose(fp);
fclose(fp); if(l==-1L)
if(l==-1L) sprintf(hbuf,"ERROR: Cannot locate help key (%s:%u) in: %s"
sprintf(hbuf,"\2 ERROR \2 Cannot locate help key (%s:%u) in:\r\n" ,p,helpline,api->helpixbfile);
" %s",p,helpline,api->helpixbfile); else {
else { if((fp=fopen(api->helpdatfile,"rb"))==NULL)
if((fp=fopen(api->helpdatfile,"rb"))==NULL) sprintf(hbuf,"ERROR: Cannot open help file: %s"
sprintf(hbuf,"\2 ERROR \2 Cannot open help file:\r\n %s" ,api->helpdatfile);
,api->helpdatfile); else {
else { if(fseek(fp,l,SEEK_SET)!=0) {
fseek(fp,l,SEEK_SET); sprintf(hbuf,"ERROR: Cannot seek to help key (%s:%u) at %ld in: %s"
fread(hbuf,HELPBUF_SIZE,1,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); fclose(fp);
} }
} }
} }
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);
} }
showbuf(WIN_MID|WIN_HLP, 0, 0, 76, api->scrn_len, "Online Help", hbuf, 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);
}
}
}
uputs(hbuf);
if(strlen(hbuf)>200) {
printf("Hit enter");
getstr(str,sizeof(str)-1);
}
}
else {
uputs(api->helpbuf);
if(strlen(api->helpbuf)>200) {
printf("Hit enter");
getstr(str,sizeof(str)-1);
}
} }
else
strcpy(hbuf,api->helpbuf);
uputs(hbuf);
if(strlen(hbuf)>200) {
printf("Hit enter");
getstr(str,sizeof(str)-1);
}
} }
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment