Re: [PATCH 1/2] nfs4-acl-tools: Fix segfault if format of the input file is incorrect

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Venkateswararao Jujjuri [jvrao@xxxxxxxxxxxxxxxxxx] wrote:
> 
> On 07/21/2011 01:35 PM, Malahal Naineni wrote:
> >The sizeof operator, when applied to a parameter declared to have array,
> >yields the size of the adjusted (pointer) type, even if the parameter
> >declaration specifies a length.
> >
> >---
> >  libnfs4acl/nfs4_ace_from_string.c |    2 +-
> >  1 files changed, 1 insertions(+), 1 deletions(-)
> >
> >diff --git a/libnfs4acl/nfs4_ace_from_string.c b/libnfs4acl/nfs4_ace_from_string.c
> >index 9d877fb..462fcc0 100644
> >--- a/libnfs4acl/nfs4_ace_from_string.c
> >+++ b/libnfs4acl/nfs4_ace_from_string.c
> >@@ -100,7 +100,7 @@ parse_alloc_fields(char *buf, char *fields[NUMFIELDS])
> >  	if (!buf)
> >  		return -EINVAL;
> >
> >-	memset(fields, 0, sizeof(fields));
> >+	memset(fields, 0, sizeof(char *) * NUMFIELDS);
> >
> >  	for (i = 0; buf[i] != '\0'; i++) {
> >  		if (buf[i] == ':')
> 
> Could it be compiler specific? It is working fine for me
> 
> 
> Test]$ cat sizeof.c
> ===========
> #include <stdio.h>
> #define NUMFIELDS 10
> main()
> {
> 	char *fields1[NUMFIELDS];
> 	char fields2[NUMFIELDS];
> 
> 	printf("sizeof(fields1):%d sizeof(char *)*NUMFIELDS:%d\n",
> sizeof(fields1), sizeof(char *)*NUMFIELDS);
> 	printf("sizeof(fields2):%d sizeof(char)*NUMFIELDS:%d\n",
> sizeof(fields2), sizeof(char)*NUMFIELDS);
> }

It works as expected in the definition scope. It doesn't work "when
applied to a parameter declared to have array". It looks like, this is
part of the C99 spec, so can't be compiler specific. Try this:

static void fun(char *a[10])
{
 	printf("sizeof returned: %d\n", sizeof(a));
}
--
To unsubscribe from this list: send the line "unsubscribe linux-nfs" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[Index of Archives]     [Linux Filesystem Development]     [Linux USB Development]     [Linux Media Development]     [Video for Linux]     [Linux NILFS]     [Linux Audio Users]     [Yosemite Info]     [Linux SCSI]

  Powered by Linux