[Toybox] sort.c patch, was: Re: PM: code style, was: Re: New Subscriber
Frank Bergmann
toybox at tuxad.com
Wed Feb 8 02:36:26 PST 2012
On Wed, Feb 08, 2012 at 09:00:10AM +0100, Frank Bergmann wrote:
> clone done. Patches submit to the list?
> My first make did throw the nasty "dereferencing type-punned pointer will
> break strict-aliasing rules". In sort.c you use TT.lines as char* and not
> char**.
Here's the stuff:
Repository:
Make generated/config.h from .config.
Compile toybox...
toys/sort.c: In function ‘sort_read’:
toys/sort.c:311: warning: dereferencing type-punned pointer will break strict-aliasing rules
[fwb at vdr toybox-cloned-1328632507]$ cd ../toybox
Local:
Make generated/config.h from .config.
Compile toybox...
[fwb at vdr toybox]$ ln -s toybox sort
[fwb at vdr toybox]$ echo -e '1\n2\n4\n3' >1
[fwb at vdr toybox]$ ./sort -c 1
sort: 1: Check line 3
[fwb at vdr toybox]$ diff -u ../toybox-cloned-1328632507/toys/sort.c toys/sort.c
--- ../toybox-cloned-1328632507/toys/sort.c 2012-02-07 17:35:07.000000000 +0100
+++ toys/sort.c 2012-02-07 17:37:41.000000000 +0100
@@ -308,7 +308,7 @@
if (CFG_SORT_BIG && (toys.optflags&FLAG_c)) {
int j = (toys.optflags&FLAG_u) ? -1 : 0;
- if (TT.lines && compare_keys((char **)&TT.lines, &line)>j)
+ if (TT.lines && compare_keys((void *)&TT.lines, &line)>j)
error_exit("%s: Check line %d\n", name, TT.linecount);
free(TT.lines);
TT.lines = (char **)line;
Your last patch which maybe introduced the warning:
diff -r 87edfe8ae99e -r 9e7aaecf0683 toys/sort.c
--- a/toys/sort.c Mon Feb 06 21:14:22 2012 -0600
+++ b/toys/sort.c Tue Feb 07 00:31:37 2012 -0600
@@ -308,11 +308,9 @@
if (CFG_SORT_BIG && (toys.optflags&FLAG_c)) {
int j = (toys.optflags&FLAG_u) ? -1 : 0;
- if (TT.linecount && compare_keys((char *)TT.lines,line)>j)
+ if (TT.lines && compare_keys((char **)&TT.lines, &line)>j)
error_exit("%s: Check line %d\n", name, TT.linecount);
-
- if (TT.lines) free(TT.lines);
- else TT.linecount = 0;
+ free(TT.lines);
TT.lines = (char **)line;
} else {
if (!(TT.linecount&63))
--
EDV Frank Bergmann Tel. 05221-9249753
LPIC-3 Linux Professional Fax 05221-9249754
Pödinghauser Str. 5 email iservice at tuxad.com
32051 Herford USt-IdNr DE237314606
More information about the Toybox
mailing list