Commit graph

12735 commits

Author SHA1 Message Date
Andrew Kelley
f559107fee use older std.mem function names
Cherry-picked bug fix was using renamed functions
2025-10-09 12:46:55 -07:00
marximimus
ca59ad658f std.crypto.tls.Client: fix infinite loop in std.Io.Writer.writeAll 2025-10-09 12:35:19 -07:00
Andrew Kelley
8ccca8472a std.fs.File.Reader.seekTo: fix one more logical position bug 2025-10-09 12:08:45 -07:00
Andrew Kelley
6a25bfc475 std.Io.Reader: rework peekDelimiterInclusive
Now it's based on calling fillMore rather than an illegal aliased stream
into the Reader buffer.

This commit also includes a disambiguation block inspired by #25162. If
`StreamTooLong` was added to `RebaseError` then this logic could be
replaced by removing the exit condition from the while loop. That error
code would represent when `buffer` capacity is too small for an
operation, replacing the current use of asserts.
2025-10-09 12:08:36 -07:00
whatisaphone
52730f3f21 Fix Reader.Limited end of stream conditions 2025-10-09 12:08:29 -07:00
Maciej 'vesim' Kuliński
6682ff2e85 std: std.fs.File fix sendFile with buffered data
fixes #25196

Co-authored-by: Andrew Kelley <andrew@ziglang.org>
2025-10-09 12:08:17 -07:00
mlugg
f661ab6c36 std.Io.Reader: fix delimiter bugs
Fix `takeDelimiter` and `takeDelimiterExclusive` tossing too many bytes
(#25132)

Also add/improve test coverage for all delimiter and sentinel methods,
update usages of `takeDelimiterExclusive` to not rely on the fixed bug,
tweak a handful of doc comments, and slightly simplify some logic.

I have not fixed #24950 in this commit because I am a little less
certain about the appropriate solution there.

Resolves: #25132

Co-authored-by: Andrew Kelley <andrew@ziglang.org>
2025-10-09 12:08:03 -07:00
Andrew Kelley
9ea4d9aa3b std: fix sendFileReading not accounting for buffer
Related to 1d764c1fdf

Test case provided by:

Co-authored-by: Kendall Condon <goon.pri.low@gmail.com>
2025-10-09 12:06:32 -07:00
Andrew Kelley
5c0ac90721 std: fix File.Writer sendfile with buffered contents
* File.Writer.seekBy passed wrong offset to setPosAdjustingBuffer.
* File.Writer.sendFile incorrectly used non-logical position.

Related to 1d764c1fdf

Test case provided by:

Co-authored-by: Kendall Condon <goon.pri.low@gmail.com>
2025-10-09 12:04:10 -07:00
Ryan Liptak
acd6ffdf69 Reader.peekDelimiterInclusive: Fix handling of stream implementations that return 0
Previously, the logic in peekDelimiterInclusive (when the delimiter was not found in the existing buffer) used the `n` returned from `r.vtable.stream` as the length of the slice to check, but it's valid for `vtable.stream` implementations to return 0 if they wrote to the buffer instead of `w`. In that scenario, the `indexOfScalarPos` would be given a 0-length slice so it would never be able to find the delimiter.

This commit changes the logic to assume that `r.vtable.stream` can both:
- return 0, and
- modify seek/end (i.e. it's also valid for a `vtable.stream` implementation to rebase)

Also introduces `std.testing.ReaderIndirect` which helps in being able to test against Reader implementations that return 0 from `stream`/`readVec`

Fixes #25428
2025-10-09 12:01:51 -07:00
tehlordvortex
ff16a7c3fa
std.Build: duplicate sub_path for LazyPath's dependency variant 2025-10-08 18:12:48 +02:00
Linus Groh
08b2fd46ab
std.c: Add missing SIG constants for serenity 2025-10-06 23:29:11 +02:00
Alex Rønne Petersen
9377cc6eef
std.zig.system: handle or1k in getExternalExecutor() 2025-10-06 23:27:20 +02:00
xdBronch
57f45cc87c
fix read of undefined in http tests 2025-10-06 23:26:15 +02:00
Ryan Liptak
78012b4845
resinator: fix an alignment problem 2025-10-02 00:13:35 +02:00
Michael Neumann
8b5e4e032b
lib/std/c: sync "struct stat" for DragonFly
* Add missing functions like ISDIR() or ISREG(). This is required to
  build the zig compiler

* Use octal notation for the S_ constants. This is how it is done for
  ".freebsd" and it is also the notation used by DragonFly in
  "sys/stat.h"

* Reorder S_ constants in the same order as ".freebsd" does. Again, this
  follows the ordering within "sys/stat.h"
2025-09-28 08:18:31 +02:00
Alex Rønne Petersen
6b1d94c539
musl: add missing fenv C dummy functions for loongarch64-linux-muslsf
https://www.openwall.com/lists/musl/2025/09/27/1

closes #25367
2025-09-28 08:18:18 +02:00
taylor.fish
9f2a200a3f
Fix PowerPC restore_rt
Clang fails to compile the CBE translation of this code ("non-ASM
statement in naked function"). Similar to the implementations of
`restore_rt` on x86 and ARM, when the CBE is in use, this commit employs
alternative inline assembly that avoids using non-immediate input
operands.
2025-09-25 03:58:58 +02:00
taylor.fish
427f0025db
Fix PowerPC syscalls causing invalid code from CBE
Fixes #25209.

On PowerPC, some registers are both inputs to syscalls and clobbered by
them. An example is r0, which initially contains the syscall number, but
may be overwritten during execution of the syscall.

musl and glibc use a `+` (read-write) constraint to indicate this, which
isn't supported in Zig. The current implementation of PowerPC syscalls
in the Zig standard library instead lists these registers as both inputs
and clobbers, but this results in the C backend generating code that is
invalid for at least some C compilers, like GCC, which doesn't support
the specifying the same register as both an input and a clobber.

This PR changes the PowerPC syscall functions to list such registers as
inputs and outputs rather than inputs and clobbers. Thanks to jacobly0
who pointed out that it's possible to have multiple outputs; I had
gotten the wrong idea from the documentation.
2025-09-24 03:50:34 +02:00
Kyle Schwarz
1f0cf7c551
glibc: guard inet-fortified.h 2025-09-24 03:50:29 +02:00
rpkak
bc567312bf
use copy_file_range syscall on linux 2025-09-24 03:50:22 +02:00
Carter Snook
6069f908e9
std: always allow spawning processes when an env map is explicitly provided (#25092)
In a library, the two `builtin.link_libc` and `builtin.output_mode ==
.Exe` checks could both be false. Thus, you would get a compile error
even if you specified an `env_map` at runtime. This change turns the
compile error into a runtime panic and updates the documentation to
reflect the runtime requirement.
2025-09-24 03:50:16 +02:00
alexrp
0e673fdab2
std.posix: remove bogus assert that SIGRTMAX < NSIG 2025-09-24 01:11:33 +02:00
Alex Rønne Petersen
b8f2fec0f2
std.pie: fix register constraint in getDynamicSymbol() for s390x (#25327)
If the compiler happens to pick `ret = r0`, then this will assemble to
`ag r0, 0` which is obviously not what we want. Using `a` instead of `r` will
ensure that we get an appropriate address register, i.e. `r1` through `r15`.

Re-enable pie_linux for s390x-linux which was disabled in
ed7ff0b693.
2025-09-24 01:11:02 +02:00
Andrew Kelley
582b96c361
std.zon.parse: fix not initializing array sentinel 2025-09-21 21:08:51 +02:00
Ryan Liptak
8d5b651c3a
Reader.defaultReadVec: Workaround bad r.end += r.vtable.stream() behavior
If `r.end` is updated in the `stream` implementation, then it's possible that `r.end += ...` will behave unexpectedly. What seems to happen is that it reverts back to its value before the function call and then the increment happens. Here's a reproduction:

```zig
test "fill when stream modifies `end` and returns 0" {
    var buf: [3]u8 = undefined;
    var zero_reader = infiniteZeroes(&buf);

    _ = try zero_reader.fill(1);
    try std.testing.expectEqual(buf.len, zero_reader.end);
}

pub fn infiniteZeroes(buf: []u8) std.Io.Reader {
    return .{
        .vtable = &.{
            .stream = stream,
        },
        .buffer = buf,
        .end = 0,
        .seek = 0,
    };
}

fn stream(r: *std.Io.Reader, _: *std.Io.Writer, _: std.Io.Limit) std.Io.Reader.StreamError!usize {
    @memset(r.buffer[r.seek..], 0);
    r.end = r.buffer.len;
    return 0;
}
```

When `fill` is called, it will call into `vtable.readVec` which in this case is `defaultReadVec`. In `defaultReadVec`:

- Before the `r.end += r.vtable.stream` line, `r.end` will be 0
- In `r.vtable.stream`, `r.end` is modified to 3 and it returns 0
- After the `r.end += r.vtable.stream` line, `r.end` will be 0 instead of the expected 3

Separating the `r.end += stream();` into two lines fixes the problem (and this separation is done elsewhere in `Reader` so it seems possible that this class of bug has been encountered before).

Potentially related issues:

- https://github.com/ziglang/zig/issues/4021
- https://github.com/ziglang/zig/issues/12064
2025-09-21 21:08:51 +02:00
Alex Rønne Petersen
90c1123d1c
std.mem: work around LoongArch inline asm bug in doNotOptimizeAway()
https://github.com/llvm/llvm-project/issues/159200
2025-09-19 12:13:21 +02:00
Frank Denis
91eab35e08
std.sort.pdq: fix out-of-bounds access in partialInsertionSort (#25253)
* std.sort.pdq: fix out-of-bounds access in partialInsertionSort

When sorting a sub-range that doesn't start at index 0, the
partialInsertionSort function could access indices below the range
start. The loop condition `while (j >= 1)` didn't respect the
arbitrary range boundaries [a, b).

This changes the condition to `while (j > a)` to ensure indices
never go below the range start, fixing the issue where pdqContext
would access out-of-bounds indices.

Fixes #25250
2025-09-18 12:47:18 +02:00
Ryan Liptak
72017d4bd5
mem.replace: Document that input/output cannot overlap 2025-09-18 12:47:18 +02:00
mlugg
83a3365bfd
std.math.big.int: normalize zero result for small multiplications
Resolves: #25221
2025-09-16 13:50:33 +02:00
George Huebner
05b7ca6356
bpf: use bitCast instead of intCast in ld_imm_impl
Any 32 bit immediate is allowed in a BPF instruction, including those
greater than the largest positive i32 value.
2025-09-16 13:50:08 +02:00
Alex Rønne Petersen
965b2ab6c3
compiler-rt: export __aeabi_read_tp for arm-freebsd
FreeBSD normally provides this symbol in libc, but it's in the
FBSDprivate_1.0 namespace, so it doesn't get included in our abilists file.
Fortunately, the implementation is identical for Linux and FreeBSD, so we can
just provide it in compiler-rt.

It's interesting to note that the same is not true for NetBSD where the
implementation is more complex to support older Arm versions. But we do include
the symbol in our abilists file for NetBSD libc, so that's fine.

closes #25215
2025-09-12 02:35:41 +02:00
Andrew Kelley
f06c3d8be7
std.debug.assertAligned: support const pointers 2025-09-12 02:33:35 +02:00
kcbanner
cbe1b4571b
webui: fixup build errors in fuzz / time_report 2025-09-12 02:32:06 +02:00
Luna Schwalbe
30ec163d14
BitcodeReader: parse blockinfo inside block
Call start/endBlock before/after `parseBlockInfoBlock` in order to not
use the current block context, which is wrong and leads to e.g. incorrect
abbrevlen being used.
2025-09-07 00:34:14 +02:00
Tadej Gašparovič
dcddbcaa60
Fix regression: std.http.Client basic authorization sending user:user instead of user:password when passed in URI 2025-09-02 22:34:51 +02:00
Brandon Mercer
b72a02c592
Populate MSG struct for OpenBSD (#25076)
* update the MSG struct with the correct values for openbsd

* add comment with link to sys/sys/socket.h

---------

Co-authored-by: Brandon Mercer <bmercer@eutonian.com>
2025-09-02 22:34:35 +02:00
Alex Rønne Petersen
d8d497ffe4
std.Thread: make unreachable errors in sleep() clearer 2025-09-02 22:33:35 +02:00
Alex Rønne Petersen
00fb5e34df
std.Target: fix alignment for int/long types on m68k 2025-09-02 22:32:17 +02:00
Ryan Liptak
cbc3c0dc59
process.totalSystemMemory: Avoid overflow on Linux when totalram is a 32-bit usize
Fixes #25038
2025-08-29 00:13:01 +02:00
tokyo4j
cb9821a827
std.os.uefi: fix type error at MemoryType.format() 2025-08-29 00:12:44 +02:00
Alex Rønne Petersen
1231c8fbbd
std.os.linux: powerpc syscalls clobber ctr and xer
https://git.musl-libc.org/cgit/musl/commit/?id=f6944eb3c4ce1c97dc39dc36d32390dc9f70b67b
2025-08-29 00:12:39 +02:00
Brandon Black
9dc3fce4c4
std.c: add correct SOMAXCONN for BSDs
Note the previous "28" here for openbsd was some kind of copy
error long ago.  That's the value of KERN.SOMAXCONN, which is an
entirely different thing.
2025-08-27 20:53:49 +02:00
Frank Denis
9c3e09cbee
Fix TLS 1.2 client key exchange to use negotiated named group (#25007)
The TLS 1.2 implementation was incorrectly hardcoded to always send the
secp256r1 public key in the client key exchange message, regardless of
which elliptic curve the server actually negotiated.

This caused TLS handshake failures with servers that preferred other curves
like X25519.

This fix:

- Tracks the negotiated named group from the server key exchange message
- Dynamically selects the correct public key (X25519, secp256r1, or
  secp384r1) based on what the server negotiated
- Properly constructs the client key exchange message with the
  appropriate key size for each curve type

Fixes TLS 1.2 connections to servers like ziglang.freetls.fastly.net
that prefer X25519 over secp256r1.
2025-08-27 20:53:42 +02:00
mlugg
a4cb636658
std.Build.WebServer: fix race
Just a typo: I wasn't actually using the duped message, so the message I
sent could be freed in this interval.
2025-08-26 21:17:38 +02:00
AdamGoertz
e323dbfd15
std.Build.Step.TranslateC: forward --cache-dir and --global-cache-dir flags 2025-08-26 17:56:23 +02:00
Ian Johnson
628357eeb6
std.Build.Step.Compile: fix race condition in args file creation
Fixes #23993

Previously, if multiple build processes tried to create the same args file, there was a race condition with the use of the non-atomic `writeFile` function which could cause a spawned compiler to read an empty or incomplete args file. This commit avoids the race condition by first writing to a temporary file with a random path and renaming it to the desired path.
2025-08-26 17:56:01 +02:00
Qun He
caa89c7601
os.linux: faccessat wrapper prefer to faccessat syscall when flags is zero.
This make `fs.Dir.access` has compatibility like the zig version before.

With this change the `zig build --search-prefix` command would work again like
the zig 0.14 version when used on Ubuntu22.04, kernel version 5.4.
2025-08-26 00:11:43 +02:00
Sardorbek Imomaliev
6f07cc95d0
add macOS handling for totalSystemMemory (#24903)
* add macos handling for totalSystemMemory

* fix return type cast for .freebsd in totalSystemMemory

* add handling for the whole Darwin family in totalSystemMemory
2025-08-26 00:11:34 +02:00
Becker A.
9ef2208e4b
Update powi.zig to fix docstring formatting
Without this change, the docs are formatted s.t. the text "Edge case rules ordered by precedence:" is appended onto the prior line of text "Underflow: Absolute value of result smaller than 1", instead of getting its own line.
2025-08-25 18:51:41 +02:00