[sr-dev] [tracker] Comment added: add a couple of missing free_to_params (mem leaks)

sip-router admin at sip-router.org
Tue Sep 20 13:02:14 CEST 2011


THIS IS AN AUTOMATED MESSAGE, DO NOT REPLY.

The following task has a new comment added:

FS#156 - add a couple of missing free_to_params (mem leaks)
User who did this - Walter Doekes (wdoekes)

----------
According to gcc -ansi it is:


$ cat struct_init.c 

#include <assert.h>
#include <stdio.h>
struct test {
	char data[4];
	unsigned number;
	void *pointer;
};
int main() {
	struct test a = {0};
	struct test b;
	struct test *p[2];
	int i, j;
	p[0] = &a;
	p[1] = &b;
	for (i = 0; i < 2; ++i) {
		for (j = 0; j < sizeof(struct test); ++j) {
			if (((char*)p[i])[j] != 0) {
				assert(i != 0);
				printf("Byte %d in %d is 0x%hhx\n", j, i, ((char*)p[i])[j]);
				break;
			}
		}
	}
	return 0;
}

$ gcc -ansi struct_init.c 

$ ./a.out 

Byte 0 in 1 is 0xd8

^-- we wanted garbage in 1, but not in 0, so it does what we expect


This corresponds with what it says here:

http://uw714doc.sco.com/en/SDK_cprog/_Initialization.html

And indeed, if we remove the 0 and use only {}, we get the same result.

If we go back further and look at this:
http://flash-gordon.me.uk/ansi.c.txt

We see:

 * "There shall be no more initializers in an initializer list than there
are objects to be initialized."

Ok, so there may be less.

 * "   The initializer for a structure or union object that has automatic
storage duration either shall be an initializer list as described
below, or ..."

Checking below:

 * "   If there are fewer initializers in a list than there are members of
an aggregate, the remainder of the aggregate shall be initialized
implicitly the same as objects that have static storage duration."

Ok. And we know that static storage duration objects are zeroed out.

 * "If an object that has static storage duration is not initialized
explicitly, it is initialized implicitly as if every member that has
arithmetic type were assigned 0 and every member that has pointer type
were assigned a null pointer constant."

I take it this answers the question.

Regards,
Walter Doekes
----------

More information can be found at the following URL:
http://sip-router.org/tracker/index.php?do=details&task_id=156#comment285

You are receiving this message because you have requested it from the Flyspray bugtracking system.  If you did not expect this message or don't want to receive mails in future, you can change your notification settings at the URL shown above.



More information about the sr-dev mailing list