[patch v2] PS3: Fix printing of os-area magic numbers

Paul Mackerras paulus at samba.org
Fri Dec 21 15:44:11 EST 2007


Geoff Levand writes:

> Fix a bug in the printing of the os-area magic numbers which assumed that
> magic numbers were zero terminated strings.  The magic numbers are represented
> in memory as integers.  If the os-area sections are not initialized correctly
> they could contained random data that would be printed to the display.

> +	u8 str[sizeof(h->magic_num) + 1];
> +	u8 *s, *d;
> +
> +	for(s = h->magic_num, d = str; s < h->magic_num + sizeof(h->magic_num);
> +		s++, d++) {
> +		*d = isprint(*s) ? *s : '.';
> +	}
> +	d[sizeof(h->magic_num)] = 0;

This last statement is wrong, because d has been incremented to point
to the last byte of str already by this stage.

It would be nicer if you pulled out the two instances of the for loop
into a little helper function.

> +	for(s = (u8*)&db->magic_num, d = str;

Why do you need the (u8*) cast in this case but not the other?

Paul.



More information about the Linuxppc-dev mailing list