summaryrefslogtreecommitdiff
path: root/sys/src/9/port/devfs.c
diff options
context:
space:
mode:
authorcinap_lenrek <cinap_lenrek@gmx.de>2013-05-27 01:12:21 +0200
committercinap_lenrek <cinap_lenrek@gmx.de>2013-05-27 01:12:21 +0200
commit410d6bea6ac0ac8d57b6c531b8829152cb503e9d (patch)
tree0ea37612d23cecbcda34d9a2aa3ed262a44d905c /sys/src/9/port/devfs.c
parentc4153b7755e3a4f3cab57ad8cbe85d18cc7cbd77 (diff)
devfs/devsd: fix waserror() and unused variable compiler problem
the compiler optimizes setting unused variables out, which is problematic if they are used in waserror() handler which the compiler isnt aware of. rearrange the code to avoid this problem.
Diffstat (limited to 'sys/src/9/port/devfs.c')
-rw-r--r--sys/src/9/port/devfs.c30
1 files changed, 18 insertions, 12 deletions
diff --git a/sys/src/9/port/devfs.c b/sys/src/9/port/devfs.c
index c5781ee17..a1ee598b4 100644
--- a/sys/src/9/port/devfs.c
+++ b/sys/src/9/port/devfs.c
@@ -748,29 +748,33 @@ rdconf(void)
} else
mustrd = 1;
- /* read it */
- cc = nil;
- c = nil;
- if (waserror()){
- if (cc != nil)
- cclose(cc);
- if (c)
- free(c);
- if (!mustrd)
+ if(waserror()){
+ if(!mustrd)
return;
nexterror();
}
+
+ /* read it */
cc = namec(s, Aopen, OREAD, 0);
+ if(waserror()){
+ cclose(cc);
+ nexterror();
+ }
devtab[cc->type]->read(cc, confstr, sizeof confstr, 0);
+ poperror();
cclose(cc);
- cc = nil;
/* validate, copy and erase config; mconfig will repopulate confstr */
if (strncmp(confstr, cfgstr, sizeof cfgstr - 1) != 0)
error("bad #k config, first line must be: 'fsdev:\\n'");
+
+ c = nil;
kstrdup(&c, confstr + sizeof cfgstr - 1);
+ if(waserror()){
+ free(c);
+ nexterror();
+ }
memset(confstr, 0, sizeof confstr);
-
/* process config copy one line at a time */
for (p = c; p != nil && *p != '\0'; p = e){
e = strchr(p, '\n');
@@ -780,8 +784,10 @@ rdconf(void)
e++;
mconfig(p, e - p);
}
- USED(cc); /* until now, can be used in waserror clause */
poperror();
+ free(c);
+
+ poperror(); /* mustrd */
}
static int