[PR #413] [CLOSED] Fix integer environment parsing #426

Closed
opened 2026-10-26 21:17:39 +00:00 by bsakaguchi · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/deepseek-ai/DeepGEMM/pull/413
Author: @OllieinCanada
Created: 8/24/2026
Status: ❌ Closed

Base: main ← Head: fix/strict-env-int-parsing


📝 Commits (2)

  • a81ac04 Fix integer environment parsing
  • ea051a0 Test and reject duplicate integer signs

📊 Changes

3 files changed (+102 additions, -3 deletions)

View changed files

➕ csrc/utils/env.hpp (+42 -0)
📝 csrc/utils/system.hpp (+5 -3)
➕ tests/test_env.cpp (+55 -0)

📄 Description

Fixes #412

Summary

Make integer environment-variable parsing deterministic and reject malformed or
out-of-range values.

Root cause

get_env<int>() ignored the return value from std::sscanf() and returned an
uninitialized local variable when an environment value did not begin with a
valid integer. Partial values such as 16abc were also silently accepted.

Fix

  • parse base-10 integers with std::from_chars() and require full consumption
  • preserve the existing acceptance of surrounding ASCII whitespace and a
    leading +
  • reject empty, malformed, partial, and out-of-range values with an error that
    identifies the environment variable
  • add a dependency-free host test covering valid boundaries and failure cases

This does not change unset-variable defaults or string environment variables.

Validation

The host-only regression test passed with GCC 9.4 in C++17 mode using:

g++ -std=c++17 -O2 -Wall -Wextra -Werror -pedantic \
    -fsanitize=undefined -fno-sanitize-recover=all \
    tests/test_env.cpp -I. -o /tmp/deepgemm-test-env
/tmp/deepgemm-test-env

The test covers zero, signed values, surrounding whitespace, INT_MIN,
INT_MAX, empty input, whitespace-only input, malformed booleans, partial
numbers, hex-like input, and positive/negative overflow. It requires no CUDA,
GPU, model, network access, or submodules.

The CUDA/GPU test suite was not run in this environment.


🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/deepseek-ai/DeepGEMM/pull/413 **Author:** [@OllieinCanada](https://github.com/OllieinCanada) **Created:** 8/24/2026 **Status:** ❌ Closed **Base:** `main` ← **Head:** `fix/strict-env-int-parsing` --- ### 📝 Commits (2) - [`a81ac04`](https://github.com/deepseek-ai/DeepGEMM/commit/a81ac04598fc87e50a355449f843b96c4e550863) Fix integer environment parsing - [`ea051a0`](https://github.com/deepseek-ai/DeepGEMM/commit/ea051a00e1a5b5c31331b221662cf552a3c38767) Test and reject duplicate integer signs ### 📊 Changes **3 files changed** (+102 additions, -3 deletions) <details> <summary>View changed files</summary> ➕ `csrc/utils/env.hpp` (+42 -0) 📝 `csrc/utils/system.hpp` (+5 -3) ➕ `tests/test_env.cpp` (+55 -0) </details> ### 📄 Description Fixes #412 ## Summary Make integer environment-variable parsing deterministic and reject malformed or out-of-range values. ## Root cause `get_env<int>()` ignored the return value from `std::sscanf()` and returned an uninitialized local variable when an environment value did not begin with a valid integer. Partial values such as `16abc` were also silently accepted. ## Fix - parse base-10 integers with `std::from_chars()` and require full consumption - preserve the existing acceptance of surrounding ASCII whitespace and a leading `+` - reject empty, malformed, partial, and out-of-range values with an error that identifies the environment variable - add a dependency-free host test covering valid boundaries and failure cases This does not change unset-variable defaults or string environment variables. ## Validation The host-only regression test passed with GCC 9.4 in C++17 mode using: ```text g++ -std=c++17 -O2 -Wall -Wextra -Werror -pedantic \ -fsanitize=undefined -fno-sanitize-recover=all \ tests/test_env.cpp -I. -o /tmp/deepgemm-test-env /tmp/deepgemm-test-env ``` The test covers zero, signed values, surrounding whitespace, `INT_MIN`, `INT_MAX`, empty input, whitespace-only input, malformed booleans, partial numbers, hex-like input, and positive/negative overflow. It requires no CUDA, GPU, model, network access, or submodules. The CUDA/GPU test suite was not run in this environment. --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
bsakaguchi 2026-10-26 21:17:39 +00:00
Sign in to join this conversation.
No labels
pull-request
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
deepseek-ai/DeepGEMM#426
No description provided.