[Tux3] [PATCH] Make sure ileaf offsets are in non-descending order

Conrad Meyer konrad at tylerc.org
Tue Sep 2 06:36:24 PDT 2008


Quoth Daniel Phillips:
> Your negative for loop is stylish.  Let's try crunching down the loop
> body a little:
> 
> int isinorder(BTREE, struct ileaf *leaf)
> {
> 	u16 *dict = (void *)leaf + btree->sb->blocksize;
> 	for (int i = 0, offset = 0, limit; i > -leaf->count; i--, offset = limit)
> 		if ((limit = dict[i]) < offset)
> 			return 0;
> 	return 1;
> }
> 
> Wow, it compresses nicely :-)

Heh, yes it does, doesn't it.

> It is still your nice clear and correct algorithm, just poked a little.
> You can integrate it with the existing (lame) check like this:
> 
> int ileaf_check(BTREE, struct ileaf *leaf)
> {
> 	char *why;
> 	why = "not an inode table leaf";
> 	if (leaf->magic != 0x90de)
> 		goto eek;
> 	why = "dict out of order";
> 	if (!isinorder(btree, leaf))
> 		goto eek;
> 	return 0;
> eek:
> 	printf("%s!\n", why);
> 	return -1;
> }

Sorry, didn't notice ileaf_check earlier. New patch coming up in a minute or 
two.

Regards,
-- 
Conrad Meyer <konrad at tylerc.org>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 197 bytes
Desc: This is a digitally signed message part.
URL: <http://phunq.net/pipermail/tux3/attachments/20080902/58b44d9b/attachment-0001.sig>
-------------- next part --------------
_______________________________________________
Tux3 mailing list
Tux3 at tux3.org
http://tux3.org/cgi-bin/mailman/listinfo/tux3


More information about the Tux3 mailing list