diff options
author | Jim Warner <james.warner@comcast.net> | 2013-08-20 00:00:00 -0500 |
---|---|---|
committer | Craig Small <csmall@enc.com.au> | 2013-08-30 22:08:25 +1000 |
commit | 819ede1a6bc25d732cf84d15c48be9ca86f336a2 (patch) | |
tree | 2c7ced0770c0a68c7b64dc5f33f27123418b20ca | |
parent | 80e678343653ccadaaf66bf719b3da9d6168d9ec (diff) | |
download | procps-ng-819ede1a6bc25d732cf84d15c48be9ca86f336a2.tar.gz |
top: correct, improve and otherwise tweak configs_read
This patch addresses the four '-Wunused-result' errors
generated whenever an optimized compile is invoked. It
also made the configs_read() guy a little more robust.
In the process, some logic was rearranged slightly and
some comments were re-indented simply for consistency.
Reference(s):
warning: ignoring return value of 'fgets', declared with attribute warn_unused_result [-Wunused-result]
warning: ignoring return value of 'fscanf', declared with attribute warn_unused_result [-Wunused-result]
Signed-off-by: Jim Warner <james.warner@comcast.net>
-rw-r--r-- | top/top.c | 38 |
1 files changed, 19 insertions, 19 deletions
@@ -3394,26 +3394,25 @@ static void configs_read (void) { fp = fopen(SYS_RCFILESPEC, "r"); if (fp) { - fbuf[0] = '\0'; - fgets(fbuf, sizeof(fbuf), fp); // sys rc file, line 1 - if (strchr(fbuf, 's')) Secure_mode = 1; - fbuf[0] = '\0'; - fgets(fbuf, sizeof(fbuf), fp); // sys rc file, line 2 - sscanf(fbuf, "%f", &Rc.delay_time); + if (fgets(fbuf, sizeof(fbuf), fp)) { // sys rc file, line 1 + Secure_mode = 1; + if (fgets(fbuf, sizeof(fbuf), fp)) // sys rc file, line 2 + sscanf(fbuf, "%f", &Rc.delay_time); + } fclose(fp); } fp = fopen(Rc_name, "r"); if (fp) { int tmp_whole, tmp_fract; - fbuf[0] = '\0'; - fgets(fbuf, sizeof(fbuf), fp); // ignore eyecatcher + if (fgets(fbuf, sizeof(fbuf), fp)) // ignore eyecatcher + ; // avoid -Wunused-result if (6 != fscanf(fp , "Id:%c, Mode_altscr=%d, Mode_irixps=%d, Delay_time=%d.%d, Curwin=%d\n" , &Rc.id, &Rc.mode_altscr, &Rc.mode_irixps, &tmp_whole, &tmp_fract, &i)) { p = fmtmk(N_fmt(RC_bad_files_fmt), Rc_name); Rc_questions = -1; - goto try_inspect_entries; // maybe a faulty 'inspect' echo + goto try_inspect_entries; // maybe a faulty 'inspect' echo } // you saw that, right? (fscanf stickin' it to 'i') Curwin = &Winstk[i]; @@ -3442,20 +3441,20 @@ static void configs_read (void) { goto default_or_error; switch (Rc.id) { - case 'f': // 3.3.0 thru 3.3.3 (procps-ng) - SETw(w, Show_JRNUMS); // fall through ! - case 'g': // current RCF_VERSION_ID - default: // and future versions? + case 'a': // 3.2.8 (former procps) + if (config_cvt(w)) + goto default_or_error; + break; + case 'f': // 3.3.0 thru 3.3.3 (procps-ng) + SETw(w, Show_JRNUMS); // fall through ! + case 'g': // current RCF_VERSION_ID + default: // and future versions? if (strlen(w->rc.fieldscur) != sizeof(DEF_FIELDS) - 1) goto default_or_error; for (x = 0; x < P_MAXPFLGS; ++x) if (P_MAXPFLGS <= FLDget(w, x)) goto default_or_error; break; - case 'a': // 3.2.8 (former procps) - if (config_cvt(w)) - goto default_or_error; - break; } #ifndef USE_X_COLHDR OFFw(w, NOHIFND_xxx | NOHISEL_xxx); @@ -3463,8 +3462,9 @@ static void configs_read (void) { } // end: for (GROUPSMAX) // any new addition(s) last, for older rcfiles compatibility... - fscanf(fp, "Fixed_widest=%d, Summ_mscale=%d, Task_mscale=%d, Zero_suppress=%d\n" - , &Rc.fixed_widest, &Rc.summ_mscale, &Rc.task_mscale, &Rc.zero_suppress); + if (fscanf(fp, "Fixed_widest=%d, Summ_mscale=%d, Task_mscale=%d, Zero_suppress=%d\n" + , &Rc.fixed_widest, &Rc.summ_mscale, &Rc.task_mscale, &Rc.zero_suppress)) + ; // avoid -Wunused-result try_inspect_entries: // we'll start off Inspect stuff with 1 'potential' blank line |