Hacktoberfest 2026 : les issues que les mainteneurs ont marquées pour octobre, ouvertes et accessibles aux débutants. Parcourir les issues Hacktoberfest

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

Fermée
#438 0 commentaires 0 réactions 0 personnes assignées Voir sur GitHub

Les mainteneurs répondent en général sous 1 jour

@peter1001136 y travaille déjà.

Depuis le 23/10/2026.

  • #441 par @jeng-a-yo — fusionnée

Évaluation

Difficulté
3/5
Temps estimé
1-2 jours
Accessibilité débutants
76/100
Type d'issue
Bug
Clarté
Clairement spécifiée
Activité
Active
Stack technique
c, javascript
Domaine
backend, testing

Piste de recherche

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.

Rédigé par le modèle d'indexation à partir du texte de l'issue.

Description

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.
Langage dominant
Rust
Étoiles
177
Forks
100
Merge moyen
1 j 11 h
PR mergées (30 j)
182

Préparer son environnement

Par où commencer

  1. Lisez l'issue en entier, puis le guide de contribution du projet.
  2. Signalez en commentaire que vous la prenez — cela évite que deux personnes fassent le même travail.
  3. Forkez le dépôt et travaillez sur une branche.
  4. Ouvrez une pull request qui référence le numéro de l'issue.

Autres issues de sysprog21/codetrial

Toutes les issues de sysprog21/codetrial

Issues similaires

Plus d'issues Rust

Recevez les nouvelles issues par e-mail

Un résumé court des issues GitHub adaptées aux débutants.