Commit Graph

17 Commits

Author SHA1 Message Date
Rob Davies 6b83413b34 Fix undefined behaviour and sign extension issues in kstrtok
Prevent read beyond the end of sep if it's an empty string.

Change to internally use unsigned char to avoid unwanted sign
extension on platforms where 'char' is signed.

Fix undefined behaviour where pointers were made to the element
before the start of `str`:
https://www.securecoding.cert.org/confluence/display/c/ARR30-C.+Do+not+form+or+use+out-of-bounds+pointers+or+array+subscripts
2018-01-11 14:30:02 +00:00
Valeriu Ohan efd09f0a00 Fixes the finished flag. 2018-01-11 14:30:02 +00:00
John Marshall cbcfcabc8f Add kgetline() to kstring.c/.h
Similar to BSD's getline() but omits the \n terminator and manages the
memory as a kstring.  Call with "(kgets_func *) fgets" to read from stdio,
or implement an fgets()-style function to read from other streams, e.g.,
a wrapper around gzgets() that reorders its parameters as per fgets().
2015-07-23 10:31:57 +01:00
James Bonfield 133bb25dfe Merged with attractivechaos/klib:
- add upstream kvsprintf and rework ksprintf
- add upstream printf attribute checks
- use our kputw (has MIN_INT bug fix)
- keep our extra functions (kputc_, kputsn_, kputl)

Added ks_str and ks_len functions for tidier manipulation of
internals.

Added error checking to all functions that allocate memory and could
potentially fail; ie return EOF or negative values as per stdio
equivalents.
2013-07-17 17:51:13 +01:00
Yorhel e44075f866 kstring: Add kvsprintf() 2013-05-07 11:56:49 +02:00
Heng Li f4f84495f5 remove ksprintf_fast(); it is not that fast... 2011-09-23 00:01:55 -04:00
Heng Li 180868ae1c added kstring_sprintf.cc 2011-07-25 23:20:13 -04:00
Heng Li 70b7fbbaa9 minor speed up 2011-07-25 23:05:44 -04:00
Heng Li 858eaffc3c minor improvement 2011-07-25 22:58:40 -04:00
Heng Li 4b91eead77 accelerate integer sprintf() a little bit 2011-07-25 22:19:20 -04:00
Heng Li 9172515431 killed a warning 2011-07-25 01:31:19 -04:00
Heng Li 535e5b71ab %g and %G should be working; more tests needed 2011-07-25 01:30:25 -04:00
Heng Li 247e867757 implemented %f/e/g in ksprintf_fast(); unfinished 2011-07-24 23:56:00 -04:00
Heng Li ed80857e9a better implementation of ksprintf_fast() 2011-07-20 11:45:11 -04:00
Heng Li fad2817ec4 added ksprintf_fast(); improve later... 2011-07-20 09:05:17 -04:00
Heng Li d8d0c5fbcb accelerate kstrtok() 2011-02-12 18:52:08 -05:00
Attractive Chaos 3cd7139ba4 Added the kstring library 2011-01-13 12:28:46 -05:00