Skip to content

fix: strip null bytes from GCC output and handle empty YAML files#1

Open
MrChocolateMoose wants to merge 2 commits into
masterfrom
fix/null-bytes-and-empty-yaml
Open

fix: strip null bytes from GCC output and handle empty YAML files#1
MrChocolateMoose wants to merge 2 commits into
masterfrom
fix/null-bytes-and-empty-yaml

Conversation

@MrChocolateMoose
Copy link
Copy Markdown

@MrChocolateMoose MrChocolateMoose commented Mar 13, 2026

Problem

When GCC -H or -E output contains embedded null bytes (common with certain toolchains and build configurations), Ceedling hits ArgumentError: string contains null byte during file path operations or YAML parsing. Separately, empty YAML files produced during preprocessing cause NoMethodError because YAML.load("") returns false, and downstream code calls .empty? on it.

These issues were worked around externally via a monkey patch loaded through RUBYOPT. This PR applies the fixes at the source.

Changes

SystemWrapper#shell_capture3 — strip null bytes from captured stdout/stderr before freezing and returning. Prevents the null byte ArgumentError from propagating into tool executor output handling, file operations, and YAML parsing.

YamlWrapper#load — return [] instead of false when YAML.load gets an empty source string. In Ruby, YAML.load("") returns false rather than nil or [], which breaks callers that do result.nil? || result.empty?.

PreprocessinatorExtractor#extract_file_as_array_from_expansion — read the full IO content and strip null bytes before the line-by-line extraction loop. GCC -E expansion files can contain embedded nulls that corrupt encoding during iteration.

mvandervoord and others added 2 commits March 12, 2026 17:24
Three bugs addressed that were previously worked around via a runtime
monkey patch (RUBYOPT=-r ceedling_fix.rb):

1. SystemWrapper#shell_capture3: Strip null bytes from stdout/stderr
   captured via Open3.capture3. GCC -H and -E can inject null bytes
   that cause ArgumentError ('string contains null byte') in
   downstream file path operations and YAML parsing.

2. YamlWrapper#load: Return [] instead of false for empty YAML files.
   YAML.load('') returns false in Ruby; callers check .nil? || .empty?
   which raises NoMethodError on false.

3. PreprocessinatorExtractor#extract_file_as_array_from_expansion:
   Strip null bytes from GCC -E preprocessed output before line-by-line
   processing. Stale or freshly-generated expansion files may contain
   embedded nulls that break encoding operations.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants