Re: [Powertop] Device list sort function bug
Paul Menzel <paulepanter at users.sourceforge.net> Wed, 11 Jul 2012 09:52:00 +0200
| Newsgroups | dev.linux.lists.powertop |
|---|---|
| Message-ID | <1341993120.4108.7.camel@mattotaupa> |
Dear Igor,
thank you for your patches!
Am Mittwoch, den 11.07.2012, 10:11 +0400 schrieb Igor Zhbanov:
> Sometimes PowerTOP dies with a Segmentation Fault while generating
> the report. Little investigation shown that it dies while sorting
> the device list. The problem is that comparison function devlist_sort
> is incorrect.
>
> The function should return true if first argument "preceeds" second.
> But when strcmp() is used, it can return -1, 0 and 1. So both -1 and 1
> values are silently converted to true, which is wrong. It confuses the sort()
> function and it crosses boundary of array.
>
> Here is the patch:
> --8<--Cut-here----------------------------------------------------------------
> diff -purN powertop-il/src/devlist.cpp powertop-il-fix/src/devlist.cpp
> --- powertop-il/src/devlist.cpp 2012-07-03 17:00:50.000000000 +0400
> +++ powertop-il-fix/src/devlist.cpp 2012-07-03 20:01:05.896232845 +0400
> @@ -273,7 +273,7 @@ static bool devlist_sort(struct devuser
> if (i->pid != j->pid)
> return i->pid< j->pid;
>
> - return strcmp(i->device, j->device);
> + return (strcmp(i->device, j->device)< 0);
> }
>
> static const char *dev_class(int line)
> --8<--------------------------------------------------------------------------
Nice find!
To decrease work for the maintainers, could you please send patches
formatted by `git format-patch`? After that you can either use `git
send-email` or copy the output into Seamonkey’s new message window.
$ git clone git://github.com/fenrus75/powertop.git
$ cd powertop
$ git config --global user.name "Igor Zhbanov"
$ git config --global user.email i.zhbanov(a)samsung.com
$ git checkout -b sort-fix # new branch for each fix
$ # apply your change
$ git commit -a # enter a nice commit message \
you should be able to use your great ones from your messages
$ git format-patch -1
Then maintainers can just apply it using the following command.
$ git am yourmessagewithpatch.mbox
If you need more help with Git, just ask.
Thanks,
Paul
signature.asc
(application/pgp-signature, 198 B)
-----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.12 (GNU/Linux) iEYEABECAAYFAk/9MKAACgkQPX1aK2wOHVgtWwCff3Itsw0SaWzTWWz1mN+JNTbl JT0AoIfjShiwqEam4ndyEchH5n2KxMtf =mQML -----END PGP SIGNATURE-----