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

From: Geoff Levand <[email-masked]>
Date: Sat, 22 Dec 2007 20:54:23 -0800

On 12/20/2007 08:44 PM, Paul Mackerras wrote:
> 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.

OK.

>> +	for(s = (u8*)&db->magic_num, d = str;
> 
> Why do you need the (u8*) cast in this case but not the other?

The types are different.  The header magic is an array of u8, the db magic
is a u32.

-Geoff