debuggers.hg

changeset 21072:099aac2cfab6

xsm/flask: Eliminate "array subscript above array bounds" warning

gcc 4.4 incorrectly reports an "array subscript above array bounds"
warning in the flask policydb code, causing the build to fail with
FLASK_ENABLE=y. Rework the code slightly to make it go away.

Signed-off-by: Stephen D. Smalley <sds@tycho.nsa.gov>
author Keir Fraser <keir.fraser@citrix.com>
date Thu Mar 11 17:15:27 2010 +0000 (2010-03-11)
parents 5b8e012641e2
children c9f795ff78b1
files xen/xsm/flask/ss/policydb.c
line diff
     1.1 --- a/xen/xsm/flask/ss/policydb.c	Thu Mar 11 08:09:58 2010 +0000
     1.2 +++ b/xen/xsm/flask/ss/policydb.c	Thu Mar 11 17:15:27 2010 +0000
     1.3 @@ -1260,7 +1260,7 @@ static int role_read(struct policydb *p,
     1.4  {
     1.5      char *key = NULL;
     1.6      struct role_datum *role;
     1.7 -    int rc, to_read = 2;
     1.8 +    int rc;
     1.9      __le32 buf[3];
    1.10      u32 len;
    1.11  
    1.12 @@ -1273,9 +1273,10 @@ static int role_read(struct policydb *p,
    1.13      memset(role, 0, sizeof(*role));
    1.14  
    1.15      if ( p->policyvers >= POLICYDB_VERSION_BOUNDARY )
    1.16 -        to_read = 3;
    1.17 +        rc = next_entry(buf, fp, sizeof(buf[0]) * 3);
    1.18 +    else
    1.19 +        rc = next_entry(buf, fp, sizeof(buf[0]) * 2);
    1.20  
    1.21 -    rc = next_entry(buf, fp, sizeof(buf[0]) * to_read);
    1.22      if ( rc < 0 )
    1.23          goto bad;
    1.24  
    1.25 @@ -1330,7 +1331,7 @@ static int type_read(struct policydb *p,
    1.26  {
    1.27      char *key = NULL;
    1.28      struct type_datum *typdatum;
    1.29 -    int rc, to_read = 3;
    1.30 +    int rc;
    1.31      __le32 buf[4];
    1.32      u32 len;
    1.33  
    1.34 @@ -1343,9 +1344,10 @@ static int type_read(struct policydb *p,
    1.35      memset(typdatum, 0, sizeof(*typdatum));
    1.36  
    1.37      if ( p->policyvers >= POLICYDB_VERSION_BOUNDARY )
    1.38 -        to_read = 4;
    1.39 +        rc = next_entry(buf, fp, sizeof(buf[0]) * 4);
    1.40 +    else
    1.41 +        rc = next_entry(buf, fp, sizeof(buf[0]) * 3);
    1.42  
    1.43 -    rc = next_entry(buf, fp, sizeof(buf[0]) * to_read);
    1.44      if ( rc < 0 )
    1.45          goto bad;
    1.46  
    1.47 @@ -1423,7 +1425,7 @@ static int user_read(struct policydb *p,
    1.48  {
    1.49      char *key = NULL;
    1.50      struct user_datum *usrdatum;
    1.51 -    int rc, to_read = 2;
    1.52 +    int rc;
    1.53      __le32 buf[3];
    1.54      u32 len;
    1.55  
    1.56 @@ -1436,9 +1438,10 @@ static int user_read(struct policydb *p,
    1.57      memset(usrdatum, 0, sizeof(*usrdatum));
    1.58  
    1.59      if ( p->policyvers >= POLICYDB_VERSION_BOUNDARY )
    1.60 -        to_read = 3;
    1.61 +        rc = next_entry(buf, fp, sizeof(buf[0]) * 3);
    1.62 +    else
    1.63 +        rc = next_entry(buf, fp, sizeof(buf[0]) * 2);
    1.64  
    1.65 -    rc = next_entry(buf, fp, sizeof(buf[0]) * to_read);
    1.66      if ( rc < 0 )
    1.67          goto bad;
    1.68