aboutsummaryrefslogtreecommitdiff
path: root/include/fmtmsg.h (unfollow)
Commit message (Expand)AuthorFilesLines
2018-11-19fix regression in access to optopt object•••commit b9410061e2ad6fe91bb3910c3adc7d4a315b7ce9 inadvertently omitted optopt from the "dynamic list", causing it to be split into separate objects that don't share their value if the main program contains a copy relocation for it (for non-PIE executables that access it, and some PIE ones, depending on arch and toolchain versions/options). Rich Felker1-0/+1
2018-11-08optimize two-way strstr and memmem bad character shift•••first, the condition (mem && k < p) is redundant, because mem being nonzero implies the needle is periodic with period exactly p, in which case any byte that appears in the needle must appear in the last p bytes of the needle, bounding the shift (k) by p. second, the whole point of replacing the shift k by mem (=l-p) is to prevent shifting by less than mem when discarding the memory on shift, in which case linear time could not be guaranteed. but as written, the check also replaced shifts greater than mem by mem, reducing the benefit of the shift. there is no possible benefit to this reduction of the shift; since mem is being cleared, the full shift is valid and more optimal. so only replace the shift by mem when it would be less than mem. Rich Felker2-2/+2
2018-11-02fix regression in setlocale for LC_ALL with per-category setting•••commit d88e5dfa8b989dafff4b748bfb3cba3512c8482e inadvertently changed the argument pased to __get_locale from part (the current ;-delimited component) to name (the full string). Rich Felker1-1/+1
2018-11-02fix failure to flush stderr when fflush(0) is called•••commit ddc947eda311331959c73dbc4491afcfe2326346 fixed the corresponding bug for exit which was introduced when commit 0b80a7b0404b6e49b0b724e3e3fe0ed5af3b08ef added support for caller-provided buffers, making it possible for stderr to be a buffered stream. Rich Felker1-1/+4
2018-11-02fix deadlock and buffered data loss race in fclose•••fflush(NULL) and __stdio_exit lock individual FILEs while holding the open file list lock to walk the list. since fclose first locked the FILE to be closed, then the ofl lock, it could deadlock with these functions. also, because fclose removed the FILE to be closed from the open file list before flushing and closing it, a concurrent fclose or exit could complete successfully before fclose flushed the FILE it was closing, resulting in data loss. reorder the body of fclose to first flush and close the file, then remove it from the open file list only after unlocking it. this creates a window where consumers of the open file list can see dead FILE objects, but in the absence of undefined behavior on the part of the application, such objects will be in an inactive-buffer state and processing them will have no side effects. __unlist_locked_file is also moved so that it's performed only for non-permanent files. this change is not necessary, but preserves consistency (and thereby provides safety/hardening) in the case where an application uses one of the standard streams after closing it while holding an explicit lock on it. such usage is of course undefined behavior. Rich Felker1-13/+19
2018-11-02__libc_start_main: slightly simplify stage2 pointer setup•••Use "+r" in the asm instead of implementing a non-transparent copy by applying "0" constraint to the source value. Introduce a typedef for the function type to avoid spelling it out twice. Alexander Monakov1-3/+4
2018-11-02remove commented-out debug printf from strstr•••this was leftover from before the initial commit. Rich Felker1-1/+0
2018-11-02fix spuriously slow check in twoway strstr/memmem cores•••mem0 && mem && ... is redundant since mem can only be nonzero when mem0 is nonzero. Rich Felker2-2/+2
2018-10-22don't omit setting errno in internal __map_file function•••a caller needs the reason for open (or fstat, albeit unlikely) failure if it's going to make decisions about continuing a path search or similar. Rich Felker1-2/+2
2018-10-22make the default locale (& a variant) failure-free cases for newlocale•••commit aeeac9ca5490d7d90fe061ab72da446c01ddf746 introduced fail-safe invariants that creating a locale_t object for the C locale or C.UTF-8 locale will always succeed. extend the guarantee to also cover the following: - newlocale(LC_ALL_MASK, "", 0) - newlocale(LC_ALL_MASK-LC_CTYPE_MASK, "C", 0) provided that the LANG/LC_* environment variables have not been changed by the program. these usages are idiomatic for getting the default locale, and for getting a locale that behaves as the C locale except for honoring the default locale's character encoding. Rich Felker1-1/+20
2018-10-22simplify newlocale and allow failure for explicit locale names•••unify the code paths for allocated and non-allocated locale objects, always using a tmp object. this is necessary to avoid clobbering the base locale object too soon if we allow for the possibility that looking up an explicitly requested locale name may fail, and makes the code simpler and cleaner anyway. eliminate the complex and fragile logic for checking whether one of the non-allocated locale objects can be used for the result, and instead just memcmp against each of them. Rich Felker1-23/+14
2018-10-20remove volatile qualification from category pointers in __locale_struct•••commit 63c188ec42e76ff768e81f6b65b11c68fc43351e missed making this change when switching from atomics to locking for modification of the global locale, leaving access to locale structures unnecessarily burdened with the restrictions of volatile. the volatile qualification was originally added in commit 56fbaa3bbe73f12af2bfbbcf2adb196e6f9fe264. Rich Felker1-1/+1
2018-10-20adapt setlocale to support possibility of failure•••introduce a new LOC_MAP_FAILED sentinel for errors, since null pointers for a category's locale map indicate the C locale. at this time, __get_locale does not fail, so there should be no functional change by this commit. Rich Felker2-12/+22
2018-10-18adjust types in FILE struct to make line buffering check less expensive•••the choice of signed char for lbf was a theoretically space-saving hack that was not helping, and was unwantedly expensive. while comparing bytes against a byte-sized member sounds easy, the trick here was that the byte to be compared was unsigned while the lbf member was signed, making it possible to set lbf negative to disable line buffering. however, this imposed a requirement to promote both operands, zero-extending one and sign-extending the other, in order to compare them. to fix this, repurpose the waiters count slot (unused since commit c21f750727515602a9e84f2a190ee8a0a2aeb2a1). while we're at it, switch mode (orientation) from signed char to int as well. this makes no semantic difference (its only possible values are -1, 0, and 1) but it might help on archs where byte access is awkward. Rich Felker1-4/+2
2018-10-18optimize internal putc_unlocked macro used in putc•••to check whether flush due to line buffering is needed, the int-type character argument must be truncated to unsigned char for comparison. if the original value is subsequently passed to __overflow, it must be preserved, adding to register pressure. since it doesn't matter, truncate all uses so the original value is no longer live. Rich Felker1-1/+2
2018-10-18fix wrong result for putc variants due to operator precedence•••the internal putc_unlocked macro was wrongly returning a meaningless boolean result rather than the written character or EOF. bug was found by reading (very surprising) asm. Rich Felker1-1/+1
2018-10-18further optimize getc/putc when locking is needed•••check whether the lock is free before loading the calling thread's tid. if so, just use a dummy tid value that cannot compare equal to any actual thread id (because it's one bit wider). this also avoids the need to save the tid and pass it to locking_getc or locking_putc, reducing register pressure. this change might slightly hurt the case where the caller already holds the lock, but it does not affect the single-threaded case, and may significantly improve the multi-threaded case, especially on archs where loading the thread pointer is disproportionately expensive like early mips and arm ISA levels. but even on i386 it helps, at least on some machines; I measured roughly a 10-15% improvement. Rich Felker2-10/+10
2018-10-18use prototype for function pointer in static link libc init barrier•••this is not needed for correctness, but doesn't hurt, and in some cases the compiler may pessimize the call assuming the callee might be variadic when it lacks a prototype. Rich Felker1-1/+1
2018-10-18fix error in constraints for static link libc init barrier•••commit 4390383b32250a941ec616e8bff6f568a801b1c0 inadvertently used "r" instead of "0" for the input constraint, which only happened to work for the configuration I tested it on because it usually makes sense for the compiler to choose the same input and output register. Rich Felker1-1/+1