summaryrefslogtreecommitdiff
path: root/sys/src/cmd/cc
diff options
context:
space:
mode:
authorcinap_lenrek <cinap_lenrek@felloff.net>2015-04-16 14:32:42 +0200
committercinap_lenrek <cinap_lenrek@felloff.net>2015-04-16 14:32:42 +0200
commit433b18ec2b54387119abdeb0a85767cd92e4a23b (patch)
tree67084a552408290bd2f64cc4a81126c3288d73bf /sys/src/cmd/cc
parent3d4fcc6c8ab02d0370919714fc08229e87f414ed (diff)
cc: catch non constant pointer initializers
char FOO[] = "abc"; /* ok */ char *BAR = FOO; /* ok */ char *BAZ = BAR; /* wrong */
Diffstat (limited to 'sys/src/cmd/cc')
-rw-r--r--sys/src/cmd/cc/dcl.c8
1 files changed, 7 insertions, 1 deletions
diff --git a/sys/src/cmd/cc/dcl.c b/sys/src/cmd/cc/dcl.c
index 968654165..7b2ae464f 100644
--- a/sys/src/cmd/cc/dcl.c
+++ b/sys/src/cmd/cc/dcl.c
@@ -381,8 +381,14 @@ init1(Sym *s, Type *t, long o, int exflag)
diag(a, "initialization of incompatible pointers: %s\n%T and %T",
s->name, t, a->type);
}
- if(a->op == OADDR)
+ if(a->op == OADDR) {
a = a->left;
+ goto gext;
+ }
+ if(a->type->etype == TIND) {
+ diag(a, "initializer is not a constant: %s", s->name);
+ return Z;
+ }
goto gext;
}