Hacktoberfest 2026: los issues que los mantenedores marcaron para octubre, abiertos y aptos para principiantes. Explorar issues de Hacktoberfest

C tests lose every result when the solution returns inf or NaN

Abierto
#438 0 comentarios 0 reacciones 0 asignados Ver en GitHub

Los mantenedores suelen responder en 1 día

Nadie ha tomado este issue todavía.

Evaluación

Dificultad
3/5
Tiempo estimado
1-2 días
Aptitud para principiantes
76/100
Tipo de issue
Error
Claridad
Bien especificado
Estado de actividad
Activo
Stack tecnológico
c, javascript
Área
backend, testing

Línea de trabajo

Start in web/compiler-explorer.js at cPrintActual and json_double_array, then read parseCompilerResults to see how invalid JSON loses the whole result set. Run the existing harness tests in tests/browser/compiler-explorer.test.js and inspect the toolchain harnesses section. Done means the C harness emits parseable JSON for non-finite doubles and the regression test confirms unaffected cases retain their results.

Escrito por el modelo de indexación a partir del texto del issue.

Descripción

Observed behavior

When a C solution returns inf or NaN for any test case of a problem that returns double or double[], the whole run is reported as a setup error and every case result is lost, including the passing ones. The test panel shows "Couldn't run your code" and "The run produced no JSON results." instead of a per-case table. This is the C counterpart of #419, which covers the Python runner.

The same solution in C++ fails only the affected cases, because C++ toJson(double) (web/compiler-explorer.js:553) and Java json(double) (:717, :760) write null for a non-finite value.

Expected behavior

Only the cases that returned a non-finite number fail, and the other cases keep their results, as in C++ and Java. For the solution below that is 3 passing cases and 3 failing ones ("negative exponent", "minimum integer exponent reciprocal path" and "cubed negative exponent").

Reproduction
  1. Start an interview on Compound Growth Factor and switch the editor to C.
  2. Replace the starter with this solution, which leaves negative exponents unfinished and returns inf for them:
double growthOverPeriods(double x, int n) {
    if (n < 0) return 1.0 / 0.0;
    double result = 1.0;
    for (int i = 0; i < n; i++) result *= x;
    return result;
}
  1. Click Run tests. The panel shows "Couldn't run your code" and "The run produced no JSON results."
  2. Switch to C++, wrap the same function in class Solution { public: ... }; and click Run tests: 3 cases pass and 3 fail.

Without a browser, the same result can be seen by building the C harness with generateHarness("c", ...) from web/compiler-explorer.js for web/judges/compound-growth-factor.json and the solution above, compiling it with cc -std=c17 and running it. Its output is:

{"results":[{"actual":1024,"timeMs":0.000},{"actual":9.261000000000001,"timeMs":0.000},{"actual":inf,"timeMs":0.000},{"actual":1,"timeMs":0.000},{"actual":inf,"timeMs":0.000},{"actual":inf,"timeMs":0.000}]}

Passing that string to parseCompilerResults returns { setupError: "The run produced no JSON results." }. A NaN is printed as -nan on glibc, which fails the same way.

CodeTrial version

codetrial 0.1.0 (2961519)

Environment

OS: Windows 11 with WSL2 (server in WSL, browser on Windows)
Browser: Google Chrome 156.0.8078.47
Access: local server at http://127.0.0.1:3100/
Language: C (C++ as the control)
Problem: Compound Growth Factor

Initial analysis

On main (2961519), cPrintActual prints a double return with a bare printf("%.17g", ...) (web/compiler-explorer.js:488), and json_double_array (:395) uses the same format for each element. Neither checks isfinite, so a non-finite value is written as inf or -nan, which are not JSON. All cases are printed as one {"results":[...]} object, so parseCompilerResults (:200) cannot parse any of it and falls back to the setup error at :215. The existing test generated harnesses emit JSON for control characters and non-finite doubles (tests/browser/compiler-explorer.test.js:169) checks only the C++ and Java sources, so the C gap is not covered.

Affected problems: Compound Growth Factor and Twin Sensor Midpoint Reading (double), and Lab Unit Converter (double[]). #425 routes list<double> to json_double_array, so Hop Depth Signal Means will reach the same printer once it lands.

Proposed change: add a C helper that writes null for a non-finite double and use it in both the double branch and json_double_array, matching C++ and Java. Add a case under toolchain harnesses in tests/browser/compiler-explorer.test.js that compiles the C harness with cc for Compound Growth Factor with a solution returning inf and NaN, and fails before the change with 3 passing and 3 failing cases expected.

Sanitized evidence
Image Image
Public data confirmation
  • I removed credentials, session tokens, candidate recordings, and personal interview content from this public report.
Lenguaje dominante
Rust
Estrellas
177
Forks
100
Merge medio
1 d 8 h
PR fusionados (30 d)
168

Preparar el entorno

Primeros pasos

  1. Lee el issue completo y luego la guía de contribución del proyecto.
  2. Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
  3. Haz un fork del repositorio y trabaja en una rama.
  4. Abre un pull request que haga referencia al número del issue.

Más de sysprog21/codetrial

Todos los issues de sysprog21/codetrial

Issues similares

Más issues de Rust

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.