Commit Graph

25 Commits

Author SHA1 Message Date
FRIGN
3b825735d8 Implement reallocarray()
Stateless and I stumbled upon this issue while discussing the
semantics of read, accepting a size_t but only being able to return
ssize_t, effectively lacking the ability to report successful
reads > SSIZE_MAX.
The discussion went along and we came to the topic of input-based
memory allocations. Basically, it was possible for the argument
to a memory-allocation-function to overflow, leading to a segfault
later.
The OpenBSD-guys came up with the ingenious reallocarray-function,
and I implemented it as ereallocarray, which automatically returns
on error.
Read more about it here[0].

A simple testcase is this (courtesy to stateless):
$ sbase-strings -n (2^(32|64) / 4)

This will segfault before this patch and properly return an OOM-
situation afterwards (thanks to the overflow-check in reallocarray).

[0]: http://www.openbsd.org/cgi-bin/man.cgi/OpenBSD-current/man3/calloc.3
2015-03-10 21:23:36 +01:00
sin
9effb224c8 expand, unexpand: Minor style fix as per the suckless guide 2015-02-17 12:14:44 +00:00
FRIGN
31572c8b0e Clean up #includes 2015-02-14 21:12:23 +01:00
FRIGN
7c578bf5b0 Scrap writerune(), introducing fputrune()
Interface and function as proposed by cls.
Code is also shorter, everything else analogous to fgetrune().
2015-02-11 20:58:00 +01:00
FRIGN
a5ae899a48 Scrap readrune(), introducing fgetrune()
Interface as proposed by cls, but internally rewritten after a few
considerations.
The code is much shorter and to the point, aligning itself with other
standard functions. It should also be much faster, which is not bad.
2015-02-11 20:16:49 +01:00
FRIGN
27b770c02c Adjust some limits to more flexibility for strtonum 2015-02-01 01:24:03 +01:00
FRIGN
fd562481f3 Convert estrto{l, ul} to estrtonum
Enough with this insanity!
2015-01-30 16:52:44 +01:00
sin
34c9083598 expand: Use strsep() for parsing the tablist 2015-01-25 18:13:32 +00:00
FRIGN
1a8dfaca37 Fix issue with negative integers passed to expand(1)
WISDOM OF THE DAY: strtoul() does not error out, when it hits a '-'-sign.
Instead, it happily carries on and fucks everything up.
2015-01-25 15:24:48 +01:00
FRIGN
5f448d9a8b Use strtoul in expand(1) and force base 10 2015-01-25 15:07:13 +01:00
FRIGN
692c11bf2b Add tablist support and a mandoc-manpage to expand(1)
and mark it as finished in the README.

This is another example showing how broken the GNU coreutils are:

$ echo -e "äää\tüüü\tööö" | gnu-expand -t "5,10,20"
äää    üüü    ööö
$ echo -e "äää\tüüü\tööö" | sbase-expand -t "5,10,20"
äää  üüü  ööö

This is due to the fact that they are still not UTF8-aware and
actually see "ä" as two single characters, expanding the "äää" with
4 spaces to a tab of length 10.
The correct way however is to expand the "äää" with 2 spaces to a
tab of length 5.
One can only imagine how this silently breaks a lot of code around
the world.
WHAT WERE THEY THINKING?
2015-01-25 14:31:02 +01:00
Brandon Mulcahy
5214191155 Handle non-power-of-two tab sizes in expand(1) 2014-12-04 22:26:08 +00:00
sin
e6df377504 Respect exit status in expand(1) 2014-11-21 17:53:33 +00:00
sin
18850f5dfa writerune() should operate on a FILE * 2014-11-21 16:34:57 +00:00
sin
5b5bb82ec0 Factor out readrune and writerune 2014-11-21 16:31:16 +00:00
sin
3de6a7510d Convert expand.c to libutf
We should librarify these chunks for now into a readrune
function.
2014-11-21 15:50:08 +00:00
FRIGN
ec8246bbc6 Un-boolify sbase
It actually makes the binaries smaller, the code easier to read
(gems like "val == true", "val == false" are gone) and actually
predictable in the sense of that we actually know what we're
working with (one bitwise operator was quite adventurous and
should now be fixed).

This is also more consistent with the other suckless projects
around which don't use boolean types.
2014-11-14 10:54:20 +00:00
FRIGN
eee98ed3a4 Fix coding style
It was about damn time. Consistency is very important in such a
big codebase.
2014-11-13 18:08:43 +00:00
sin
0c5b7b9155 Stop using EXIT_{SUCCESS,FAILURE} 2014-10-02 23:46:59 +01:00
Tuukka Kataja
612e09af7e Implement -i flag for expand 2014-06-09 17:00:33 +01:00
Tuukka Kataja
6561567597 Fix expand when one of multiple files can't be opened
Currently when multiple files are specified and one of them can't be opened,
expand doesn't correctly skip over the missing file. This patch fixes that.
2014-06-09 17:00:23 +01:00
sin
b8edf3b4ee Add weprintf() and replace fprintf(stderr, ...) calls
There is still some programs left to be updated for this.

Many of these programs would stop on the first file that they
could not open.
2013-11-13 11:41:43 +00:00
sin
b5a511dacf Exit with EXIT_SUCCESS/EXIT_FAILURE instead of 0 and 1
Fixed for consistency purposes.
2013-10-07 16:44:22 +01:00
sin
83c2c3d1f5 Add 'not implemented' errors for unimplemented flags
These used to live in TODO but we got rid off them.  Make sure
we keep track of what we want to support by printing a message
when those flags are unimplemented.
2013-10-05 13:51:45 +01:00
stateless
e28c17c7cc Add expand(1)
Signed-off-by: Christoph Lohmann <20h@r-36.net>
2013-06-19 20:01:10 +02:00