Commit Graph

21742 Commits

Author SHA1 Message Date
Lenard Mollenkopf 37920d33ac Replace references to C2x with C23
Signed-off-by: Lenard Mollenkopf <newlib@lenardmollenkopf.de>
2024-11-04 11:44:55 +01:00
Lenard Mollenkopf 5e0fb305a8 sys/features.h: Use _ISOC23_SOURCE instead of _ISOC23_SOURCE and remap _ISOC2x_SOURCE to _ISOC23_SOURCE
Signed-off-by: Lenard Mollenkopf <newlib@lenardmollenkopf.de>
2024-11-04 11:44:55 +01:00
Takashi Yano c607889824 Cygwin: sigfe: Fix a bug that signal handler destroys fpu states
Previously, sigfe had a bug that the signal handler destroys fpu state.
This is caused by fninit instruction in sigdelayed. With this patch,
saving/restoring the FPU/SIMD state is done using fxsave/fxrstor or
xsave/xrstor rather than fnstcw/fldcw, stmxcsr/ldmxcsr and push/pop
xmm0-xmm15. Since xsave/xrstor is used, not only x87/MMX/SSE states
but also AVX/AVX2/AVX-512 states can be maintained unlike before.
Addresses: https://cygwin.com/pipermail/cygwin/2024-October/256503.html

Fixes: ed89fbc3ff ("* gendef (sigdelayed (x86_64)): Save and restore FPU control word.")
Reported-by: Christian Franke <Christian.Franke@t-online.de>
Suggested-by: Brian Inglis <Brian.Inglis@SystematicSW.ab.ca>
Reviewed-by: Corinna Vinschen <corinna@vinschen.de>
Signed-off-by: Takashi Yano <takashi.yano@nifty.ne.jp>
2024-11-01 04:56:27 +09:00
Takashi Yano 7ed9adb356 Cygwin: pipe: Switch pipe mode to blocking mode by default
Previously, cygwin read pipe used non-blocking mode although non-
cygwin app uses blocking-mode by default. Despite this requirement,
if a cygwin app is executed from a non-cygwin app and the cygwin
app exits, read pipe remains on non-blocking mode because of the
commit fc691d0246. Due to this behaviour, the non-cygwin app
cannot read the pipe correctly after that. Similarly, if a non-
cygwin app is executed from a cygwin app and the non-cygwin app
exits, the read pipe mode remains on blocking mode although cygwin
read pipe should be non-blocking mode.

These bugs were provoked by pipe mode toggling between cygwin and
non-cygwin apps. To make management of pipe mode simpler, this
patch has re-designed the pipe implementation. In this new
implementation, both read and write pipe basically use only blocking
mode and the behaviour corresponding to the pipe mode is simulated
in raw_read() and raw_write(). Only when NtQueryInformationFile
(FilePipeLocalInformation) fails for some reasons, the raw_read()/
raw_write() cannot simulate non-blocking access. Therefore, the pipe
mode is temporarily changed to non-blocking mode.

Moreover, because the fact that NtSetInformationFile() in
set_pipe_non_blocking(true) fails with STATUS_PIPE_BUSY if the pipe
is not empty has been found, query handle is not necessary anymore.
This allows the implementation much simpler than before.

Addresses: https://github.com/git-for-windows/git/issues/5115
Fixes: fc691d0246 ("Cygwin: pipe: Make sure to set read pipe non-blocking for cygwin apps.");
Reported-by: isaacag, Johannes Schindelin <Johannes.Schindelin@gmx.de>
Reviewed-by: Corinna Vinschen <corinna@vinschen.de>, Ken Brown <kbrown@cornell.edu>
Signed-off-by: Takashi Yano <takashi.yano@nifty.ne.jp>
2024-11-01 04:50:45 +09:00
Corinna Vinschen 1f05c04059 Cygwin: pipe: fix shift value
The expression computing the next-less-power of 2 for the next write
when the pipe buffer is getting filled up allows negative shift values.
This works on Intel CPUs because the shift expression only evaluates the
5 LSBs, but it's undefined behaviour per the C standard.  Use the
correct expression to get a positive shift value.

Fixes: 170e6badb6 ("Cygwin: pipe: improve writing when pipe buffer is almost full")
Reported-by: Takashi Yano <takashi.yano@nifty.ne.jp>
Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2024-10-31 13:15:29 +01:00
Takashi Yano 04f386e9af Cygwin: console: Inherit pcon hand over from parent pty
There was a long-standing issue that pseudo console ownership could
not hand over from the process whose ctty is /dev/cons* rather than
/dev/pty*. This problem happens when a cygwin app starts non-cygwin
app in a pty, then the non-cygwin app starts multiple cygwin apps,
and the non-cygwin app ends before the second cygwin apps end.
In this case, the stub process of the non-cygwin app hands over the
ownership of pcon to one of the second cygwin apps, however, this
app does not hand over the ownership of pcon to another second
cygwin app. This is due to the fact that the hand-over feature is
implemented only in fhandler_pty_slave but not in fhandler_console.

With this patch, the second cygwin apps check if their console device
is inside a pseudo console, and if so, it tries to hand over the
ownership of the pseudo console to anther process that is attached
to the same pseudo console.

Addresses: https://cygwin.com/pipermail/cygwin/2024-February/255388.html
Fixes: 253352e796 ("Cygwin: pty: Allow multiple apps to enable pseudo console simultaneously.")
Reported-by: lmari Lauhakangas <ilmari.lauhakangas@libreoffice.org>, Hossein Nourikhah <hossein@libreoffice.org>
Signed-off-by: Takashi Yano <takashi.yano@nifty.ne.jp>
2024-10-31 15:34:56 +09:00
Takashi Yano ae181b0ff1 Cygwin: lockf: Make lockf() return ENOLCK when too many locks
Previously, lockf() printed a warning message when the number of locks
per file exceeds the limit (MAX_LOCKF_CNT). This patch makes lockf()
return ENOLCK in that case rather than printing the warning message.

Addresses: https://cygwin.com/pipermail/cygwin/2024-October/256528.html
Fixes: 31390e4ca6 ("(inode_t::get_all_locks_list): Use pre-allocated buffer in i_all_lf instead of allocating every lock.  Return pointer to start of linked list of locks.")
Reported-by: Christian Franke <Christian.Franke@t-online.de>
Reviewed-by: Corinna Vinschen <corinna@vinschen.de>
Signed-off-by: Takashi Yano <takashi.yano@nifty.ne.jp>
2024-10-31 15:34:45 +09:00
Takashi Yano f9cc21dc00 Cygwin: lockf: Fix adding a new lock over multiple locks
Previously, adding a new lock by lockf() over multiple existing locks
failed. This is due to a bug that lf_setlock() tries to create a lock
that has already been created. This patch fixes the issue.

Addresses: https://cygwin.com/pipermail/cygwin/2024-October/256528.html
Fixes: a998dd7055 ("* flock.cc: Implement all advisory file locking here.")
Reported-by: Christian Franke <Christian.Franke@t-online.de>
Reviewed-by: Corinna Vinschen <corinna@vinschen.de>
Signed-off-by: Takashi Yano <takashi.yano@nifty.ne.jp>
2024-10-31 15:34:32 +09:00
Lenard Mollenkopf 5e6eb2f200 sys/features.h: Spelling _ISOC2x_SOURCE is not C11 2024-10-28 13:49:28 +01:00
Christian Franke 6af8fea4bb Cygwin: timer_delete: Fix return value
timer_delete() always returned failure.  This issue has been
detected by 'stress-ng --hrtimers 1'.

Fixes: 229ea3f23c ("Cygwin: posix timers: reimplement using OS timer")
Signed-off-by: Christian Franke <christian.franke@t-online.de>
2024-10-23 13:25:09 +02:00
Christian Franke bdd06f82a1 cygwin: pread/pwrite: prevent EBADF error after fork()
If the parent process has already used pread() or pwrite(), these
functions fail with EBADF if used on the inherited fd.  Ensure that
fix_after_fork() is called to invalidate the prw_handle.  This issue
has been detected by 'stress-ng --pseek 1'.

Fixes: c36cd56c54 ("* fhandler.cc (fhandler_base::open): Drop local create_options variable.")
Signed-off-by: Christian Franke <christian.franke@t-online.de>
2024-10-23 11:56:59 +02:00
Fabian Schriever 1b7c72fdcc powf: Fixed another precision bug in powf() (FreeBSD)
Fixed another precision bug in powf(). This one is in the computation
[t=p_l+p_h High]. We multiply t by lg2_h, and want the result to be
exact. For the bogus float case of the high-low decomposition trick, we
normally discard the lowest 12 bits of the fraction for the high part,
keeping 12 bits of precision. That was used for t here, but it doesnt't
work because for some reason we only discard the lowest 9 bits in the
fraction for lg2_h.  Discard another 3 bits of the fraction for t to
compensate.

This bug gave wrong results like:

powf(0.9999999, -2.9999995) = 1.0000002 (should be 1.0000001)
hex values: 3F7FFFFF C03FFFFE 3F800002 3F800001

As explained in the log for the previous commit, the bug is normally
masked by doing float calculations in extra precision on i386's, but is
easily detected by ucbtest on systems that don't have accidental extra
precision.

Reference: 5f20e5ce7f
Original Author: Bruce Evans
2024-09-19 13:58:50 -04:00
Fabian Schriever fb76697745 powf: Fixed 2 bugs in the computation /* t_h=ax+bp[k] High */. (FreeBSD)
(1) The bit for the 1.0 part of bp[k] was right shifted by 4.  This
    seems to have been caused by a typo in converting e_pow.c to
    e_powf.c.
(2) The lower 12 bits of ax+bp[k] were not discarded, so t_h was
    actually plain ax+bp[k].  This seems to have been caused by a logic
    error in the conversion.

These bugs gave wrong results like:

    powf(-1.1, 101.0) = -15158.703 (should be -15158.707)
      hex values: BF8CCCCD 42CA0000 C66CDAD0 C66CDAD4

Fixing (1) gives a result wrong in the opposite direction
(hex C66CDAD8), and fixing (2) gives the correct result.

ucbtest has been reporting this particular wrong result on i386 systems
with unpatched libraries for 9 years.  I finally figured out the extent
of the bugs.  On i386's they are normally hidden by extra precision.
We use the trick of representing floats as a sum of 2 floats (one much
smaller) to get extra precision in intermediate calculations without
explicitly using more than float precision.  This trick is just a
pessimization when extra precision is available naturally (as it always
is when dealing with IEEE single precision, so the float precision part
of the library is mostly misimplemented).  (1) and (2) break the trick
in different ways, except on i386's it turns out that the intermediate
calculations are done in enough precision to mask both the bugs and
the limited precision of the float variables (as far as ucbtest can
check).

ucbtest detects the bugs because it forces float precision, but this
is not a normal mode of operation so the bug normally has little effect
on i386's.

On systems that do float arithmetic in float precision, e.g., amd64's,
there is no accidental extra precision and the bugs just give wrong
results.

Reference: 12be4e0d5a
Original Author: Bruce Evans
2024-09-19 13:58:31 -04:00
Fabian Schriever 5fcf159b99 powf: Fix the hi+lo decomposition for 2/(3ln2) (FreeBSD)
The decomposition needs to be into 12+24 bits of precision for extra-
precision multiplication, but was into 13+24 bits. On i386 with -O1 the
bug was hidden by accidental extra precision, but on amd64, in 2^32
trials the bug caused about 200000 errors of more than 1 ulp, with a
maximum error of about 80 ulps. Now the maximum error in 2^32 trials
on amd64 is 0.8573 ulps. It is still 0.8316 ulps on i386 with -O1.

The nearby decomposition of 1/ln2 and the decomposition of 2/(3ln2) in
the double precision version seem to be sub-optimal but not broken.

Reference: b4437c3d32
Original Author: Bruce Evans
2024-09-19 13:58:12 -04:00
Jeff Johnston 5a9fe58014 Make sure mallinfo structure matches newlib's malloc.h 2024-09-16 19:21:46 -04:00
yang.zhang 1b3dcfdc6f Replace __restrict with __restrict_arr in regex.h
when a C++ source file include this header file, it would build fail.

Signed-off-by: yang.zhang <zhangyang01@kylinos.cn>
2024-09-02 22:23:50 +02:00
Alexey Lapshin cc0d1bf2f1 newlib: esp: add dirent.h header file
Support dirent in *-esp-* toolchains
2024-09-02 22:16:59 +02:00
Alexey Lapshin 48f1655c95 newlib: xtensa: remove sys/xtensa. use machine/xtensa
Remove sys/xtensa that is actually duplicate newlib's code.
Move used code to machine/xtensa or to libgloss
2024-09-02 22:16:59 +02:00
Takashi Yano f78009cb1c Cygwin: pipe: Fix a regression that raw_write() slows down
After the commit 7f3c225325, writing to pipe extremely slows down.
This is because cygwait(select_sem, 10, cw_cancel) is called even
when write operation is already completed. With this patch, the
cygwait() is called only if the write operation is not completed.

Addresses: https://cygwin.com/pipermail/cygwin/2024-August/256398.html
Fixes: 7f3c225325 ("Cygwin: pipe: handle signals explicitely in raw_write")
Reported-by: Jim Reisert AD1C <jjreisert@alum.mit.edu>
Reviewed-by: Corinna Vinschen <corinna@vinschen.de>
Signed-off-by: Takashi Yano <takashi.yano@nifty.ne.jp>
2024-09-02 20:12:39 +09:00
Takashi Yano 84d77e5918 Cygwin: console: Disable cons_master_thread in win32-input-mode
When win32-input-mode (which is supported by Windows Termainal) is
set by "\033[?9001h", cons_master_thread does not work properly and
consumes larger and larger memory space. This is because sending
event by WriteConsoleInput() is translated into the sequence that
is used by win32-input-mode. Due to this behaviour, write-back
of the INPUT_RECORDs does not work as expected. With this patch,
cons_master_thread is disabled on win32-input-mode where the signal
keys such as Ctrl-C, Ctrl-Z etc. never comes.

Addresses: https://cygwin.com/pipermail/cygwin/2024-August/256380.html
Fixes: ff4440fcf7 ("Cygwin: console: Introduce new thread which handles input signal.")
Reported-by: Adamyg Mob <adamyg.mob@gmail.com>
Signed-off-by: Takashi Yano <takashi.yano@nifty.ne.jp>
2024-08-31 19:05:49 +09:00
Corinna Vinschen a422196c56 Cygwin: add release message for latest pipe changes
Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2024-08-22 21:24:35 +02:00
Corinna Vinschen 8d7b09279c Cygwin: Add locale patches to release message
Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2024-08-22 21:22:41 +02:00
Corinna Vinschen d78ca12ab4 locales: Fix definition of lc_messages_T::codeset
nl_langinfo_l accesses lc_messages_T::codeset as soon as
__HAVE_LOCALE_INFO__ is defined, but codeset only exists
if __HAVE_LOCALE_INFO_EXTENDED__ is defined.

Fix this by defining lc_messages_T::codeset depending on
__HAVE_LOCALE_INFO__.

Fixes: ac7f1d5e93 ("Get rid of LCID, reformat type definitions in setlocale.h")
Reported-by: Inglis <Brian.Inglis@SystematicSW.ab.ca>
Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2024-08-22 21:21:51 +02:00
Corinna Vinschen ea1a458d20 nl_langinfo_l: drop erroneus messages::codeset entry
The nl_ext array contains offsets into the extended info of
locale structures, the index being equivalent to the nl_item
values in langinfo.h.

For the lc_messages_T struct, nl_ext erroneusly contains an
entry for the codeset member, which is in fact not part of the
extended info in nl_item.  However, due to that, the offsets for
subsequent entries are off by one.

Fix this by dropping the messages::codeset entry from nl_ext.

Fixes: d47d5b850b ("Extend locale support to maintain wide char values of native strings")
Reported-by: Brian Inglis <Brian.Inglis@systematicsw.ab.ca>
Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2024-08-22 21:15:44 +02:00
Yuriy Kolerov 820dd5009b arc64: Add port for Synopsys DesignWare ARCv3 ISA
Synopsys ARCv3 ISA includes 32-bit ARC HS5x targets and
64-bit ARC HS6x targets. Both CPU families are placed
in "arc64" subdirectories as it done for GCC port.
Target name arc64 is used for historical reasons and
Synopsys ARCv3 baremetal toolchains contain multilib
configurations both for 32-bit and 64-bit families.
arc32 target name is reserved for 32-bit ARC HS5x
targets in case of non-multilib 32-bit builds.

Note that libgloss libraries for ARCv3 are compatible with
libgloss for ARCv1/2. Thus, Makefile.inc for libgloss uses
sources from libgloss/arc directory except crtX.S files.

Co-authored-by: Shahab Vahedi <list@vahedi.org>
Co-authored-by: Claudiu Zissulescu <claziss@gmail.com>
Co-authored-by: Bruno Mauricio <brunoasmauricio@gmail.com>
Co-authored-by: Luis Silva <luis.m.silva99@hotmail.com>
Signed-off-by: Yuriy Kolerov <ykolerov@synopsys.com>
2024-08-21 15:32:22 -04:00
Yuriy Kolerov 59f4a286a4 Update config.sub to GCC master branch version
New config.sub contains support of Synopsys ARCv3 targets. It's
necessary for further porting Newlib for ARCv3.

config.guess has not been updated yet in GCC.

Signed-off-by: Yuriy Kolerov <ykolerov@synopsys.com>
2024-08-21 15:18:36 -04:00
Claudiu Zissulescu d58915acc7 Use ldflags instead of LDFLAGS in newlib.exp
This variable was accidentally renamed earlier. It must be
ldflags according to DejaGNU documentation.

Signed-off-by: Claudiu Zissulescu <claziss@gmail.com>
2024-08-21 11:16:14 +02:00
Jeff Johnston 86d63f0554 Add new version of Synopsys license. 2024-08-20 18:30:52 -04:00
Yuriy Kolerov b99f27c25f arc: libgloss: Prepare for porting to ARCv3
There are 3 families of Synopsys DeisgnWare ARC processors:
ARCompact/ARCv1 (32-bit), ARCv2 (32-bit) and ARCv3 (32-bit
and 64-bit targets). Upstream Newlib supports only ARCv1/2.
This commit prepares ARCv1/2 libgloss port to be reused by
ARCv3 port (except crt* files). Note that __ARC64__ macro
stands for all ARCv3 targets.

Signed-off-by: Yuriy Kolerov <ykolerov@synopsys.com>
2024-08-20 18:24:15 -04:00
Yuriy Kolerov 03f4e346f4 arc: libgloss: Use exit code in _exit_halt for nSIM
nSIM simulator supports exit codes. However, it's necessary
to pass an exit code to _exit_halt, otherwise it's undefined.

Signed-off-by: Yuriy Kolerov <ykolerov@synopsys.com>
2024-08-20 18:24:00 -04:00
Alexey Brodkin eef062451f arc: libgloss: Accommodate MetaWare's standard symbol names
It makes it usable with standard symbol names defined in default
linker scripts of the MetaWare toolchain.

Signed-off-by: Alexey Brodkin <abrodkin@synopsys.com>
2024-08-20 18:23:34 -04:00
Alexey Brodkin 16accfa08d arc: Remove @ from symbol references in assembly
There's no semantic change, it's only to make the same code
compilable with MetaWare toolchian, which actually assumes
@x as a full name, not omitting @.

Signed-off-by: Alexey Brodkin <abrodkin@synopsys.com>
2024-08-20 18:23:20 -04:00
Claudiu Zissulescu 3e9f6a005c arc: Use __ARC_UNALIGNED__ compiler macro
Replace __ARC_ALIGNED_ACCESS__ macro with the compiler defined
macro __ARC_UNALIGNED__ and improve file comments.

Signed-off-by: Claudiu Zissulescu <claziss@gmail.com>
2024-08-20 18:23:06 -04:00
Yuriy Kolerov 2c46bffba0 arc: libgloss: Clean MetaWare hostlink documentation
Signed-off-by: Yuriy Kolerov <ykolerov@synopsys.com>
2024-08-20 18:22:49 -04:00
Alexey Brodkin d7d4fe4f4a arc: libgloss: Switch from .balign to .align
.align is supported by both GCC & MetaWare compiler for ARC,
yet implements the same semantics as .balign which only works
with GCC.

Signed-off-by: Alexey Brodkin <abrodkin@synopsys.com>
2024-08-20 18:21:52 -04:00
Yuriy Kolerov c3561210ed arc: libgloss: Fix define guard in nsim-syscall.h
Signed-off-by: Yuriy Kolerov <ykolerov@synopsys.com>
2024-08-20 18:21:28 -04:00
Jordi Sanfeliu e5689df37d Fix glob() function
Fixed glob() function to return GLOB_NOMATCH if pattern does
not match any existing pathname (and GLOB_NOCHECK was not set in flags).
2024-08-20 14:42:03 +02:00
Joel Sherrill a86f468f96 newlib/libc/include/sys/tree.h: Add deprecation warning 2024-08-19 12:04:17 +02:00
Joel Sherrill f6eb96418a libc/include/sys/tree.h: Re-add sys/tree.h
Reverts 1339af4467
2024-08-19 12:04:17 +02:00
Corinna Vinschen 686e46ce71 Cygwin: pipe: do short writes only once in nonblocking case too
If a nonblocking write requires short writes, just try it once
as in the blocking case.  After all, we are nonblocking, so
don't loop unnecessarily.

Fixes: 170e6badb6 ("Cygwin: pipe: improve writing when pipe buffer is almost full")
Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2024-08-19 11:51:14 +02:00
Corinna Vinschen 1ed909e047 Cygwin: pipe: fix comparison
There's no reason to overwrite len1 with align if they are the same value.

Fixes: 170e6badb6 ("Cygwin: pipe: improve writing when pipe buffer is almost full")
Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2024-08-19 11:44:42 +02:00
Corinna Vinschen 170e6badb6 Cygwin: pipe: improve writing when pipe buffer is almost full
So far fhandler_pipe_fifo::raw_write always returns -1/EINTR
if a signal arrived.  Linux does not do that if there's still
space left in the pipe buffer.

The Linux buffer handling can't be emulated by Cygwin, but we
can do something similar which makes it much more likely to still
write successfully even if the buffer is almost full.

Utilize pipe_data_available to return valid pipe buffer usage
to raw_write, allowing a more sophisticated way to fill the
buffer while maintaining comaptibility with non-Cygwin pipes.

Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2024-08-18 22:07:16 +02:00
Corinna Vinschen 1c5f4dcdc5 Cygwin: select: set pipe writable only if PIPE_BUF bytes left
Linux select(2) returns the pipe as writable if at least one
free page (4K onl most systems) is left in a page-oriented buffer
handling. This is the same as PIPE_BUF.

Emulate this behaviour by only returning the pipe as writable
if at least 4K space is left in the buffer.

Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2024-08-18 21:55:52 +02:00
Corinna Vinschen 7f3c225325 Cygwin: pipe: handle signals explicitely in raw_write
The simple cygwait call in fhandler_pipe_fifo::raw_write doesn't
take the SA_RESTART setting into account. Move handling the
signal into raw_write.

Fixes: 4b25687ea3 ("Cygwin: fhandler_pipe: add raw_read and raw_write")
Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2024-08-18 21:40:51 +02:00
Corinna Vinschen b2e05e03df stdlib.h: define __itoa/__utoa while building newlib
This avoids a `__utoa undefined' warning when building newlib
for Cygwin.  We still need to export the symbols for backward
compatibility.

Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2024-08-15 20:54:57 +02:00
Corinna Vinschen 8d4ea8ba68 Cygwin: getopt.h: fix a comment
Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2024-08-15 20:54:53 +02:00
Corinna Vinschen ca31784fef Fix POSIX guards for POSIX.1-2024 extensions
Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2024-08-15 20:42:04 +02:00
Corinna Vinschen 13c89a620b features.h: support POSIX.1-2024
TBD: Align _GNU_SOURCE, too?

Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2024-08-15 17:40:06 +02:00
Corinna Vinschen c6f14f261a features.h: fix whitespace
Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2024-08-15 17:36:54 +02:00
Jon Turney 4eb9397b6c
Cygwin: Avoid use-after-free warnings in __set_lc_time_from_win() etc.
Rewrite to avoid new use-after-free warnings about realloc(), seen with
gcc 12, e.g.:

> In function ‘void rebase_locale_buf(const void*, const void*, const char*, const char*, const char*)’,
>     inlined from ‘int __set_lc_time_from_win(const char*, const lc_time_T*, lc_time_T*, char**, wctomb_p, const char*)’ at ../../../../src/winsup/cygwin/nlsfuncs.cc:705:25:
> ../../../../src/winsup/cygwin/nlsfuncs.cc:338:24: error: pointer ‘new_lc_time_buf’ may be used after ‘void* realloc(void*, size_t)’ [-Werror=use-after-free]
>   338 |       *ptrs += newbase - oldbase;
>       |                ~~~~~~~~^~~~~~~~~
> ../../../../src/winsup/cygwin/nlsfuncs.cc: In function ‘int __set_lc_time_from_win(const char*, const lc_time_T*, lc_time_T*, char**, wctomb_p, const char*)’:
> ../../../../src/winsup/cygwin/nlsfuncs.cc:699:44: note: call to ‘void* realloc(void*, size_t)’ here
>   699 |               char *tmp = (char *) realloc (new_lc_time_buf, len);

Technically, it's UB to later refer to the realloced pointer (even just
for offset computations, without deferencing it), so switch to using
malloc() to create the resized copy.

Signed-off-by: Jon Turney <jon.turney@dronecode.org.uk>
2024-08-13 19:44:00 +01:00