Bug#931977: startpar: uninitialized variable

Dmitry Bogatov KAction at debian.org
Sat Jul 13 09:29:00 BST 2019

Package: startpar
Version: 0.61-1
Severity: normal
X-Debbugs-Cc: Jesse Smith <jessefrgsmith at yahoo.ca>

Dear Maintainer,

GCC complains about uninialized variable

	proc.c: In function ‘detect_consoles’:
	proc.c:180:16: warning: ‘tail’ may be used uninitialized in this function [-Wmaybe-uninitialized]
	      tail->tty = name;

and it seems it is right:

	struct console *restrict tail;
	if (posix_memalign((void*)&tail, sizeof(void*), alignof(typeof(struct console))) != 0)
		perror("memory allocation");
	tail->next = (struct console*)0;
	tail->tty = name;

According to posix_memalign(3), if posix_memalign functions fails, it
does not alter first argument "tail", which is not initialized otherwise, and
dereference "tail" anyway: perror() just prints error, it does not
affect control flow.

Also, second argument is "sizeof(void*)" which is no bigger then 8,
while malloc(3) guarantees alignment of 8.

So, this quite complicated-looking call to posix_memalign(3) can be
simplified to:

	tail = malloc(sizeof(*tail));
	if (!tail) {
Note, that I send and fetch email in batch, once in a few days.
Please, mention in body of your reply when you add or remove recepients.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 833 bytes
Desc: not available
URL: <http://www.chiark.greenend.org.uk/pipermail/debian-init-diversity/attachments/20190713/6dbc8b75/attachment.sig>

More information about the Debian-init-diversity mailing list