C tests lose every result when the solution returns inf or NaN
Les mainteneurs répondent en général sous 1 jour
É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
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
- Start an interview on Compound Growth Factor and switch the editor to C.
- Replace the starter with this solution, which leaves negative exponents unfinished and returns
inffor 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;
}
- Click Run tests. The panel shows "Couldn't run your code" and "The run produced no JSON results."
- 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
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
- Aucun Dockerfile ni fichier Docker Compose
- Aucun modèle de pull request
- Lire le guide de contribution
Par où commencer
- Lisez l'issue en entier, puis le guide de contribution du projet.
- Signalez en commentaire que vous la prenez — cela évite que deux personnes fassent le même travail.
- Forkez le dépôt et travaillez sur une branche.
- Ouvrez une pull request qui référence le numéro de l'issue.
Autres issues de sysprog21/codetrial
-
Selecting a pen color leaves Example drawing in eraser modePeut-être pris @Aa99841 l’a pris aujourd’hui. Ouverte
Difficulté 2/5 1-3 heures Accessibilité débutants 78/100
sysprog21/codetrial#437 · 4 commentaires · 1 personne assignée ·
Les mainteneurs répondent en général sous 1 jour
-
Python tests lose every result when the solution returns inf or NaNPeut-être pris @shensyuan l’a pris il y a 2 jours. Ouverte
Difficulté 2/5 1-3 heures Accessibilité débutants 77/100
sysprog21/codetrial#419 · 3 commentaires · 1 personne assignée ·
Les mainteneurs répondent en général sous 1 jour
-
Allow deselecting a chosen problem card by clicking it againPeut-être pris @woohsin l’a pris il y a 2 jours. Ouverte
Difficulté 2/5 1-3 heures Accessibilité débutants 68/100
sysprog21/codetrial#392 · 4 commentaires · 1 personne assignée ·
Les mainteneurs répondent en général sous 1 jour
-
Audio output can be confirmed without playing a test soundPeut-être pris @ChenYingHan1121 l’a pris il y a 5 jours. Ouverte
Difficulté 2/5 1-3 heures Accessibilité débutants 62/100
sysprog21/codetrial#359 · 5 commentaires · 1 personne assignée ·
Les mainteneurs répondent en général sous 1 jour
-
Add a Copy code button to the final reportPeut-être pris @yansawu l’a pris il y a 5 jours. Ouverte
Difficulté 2/5 1-3 heures Accessibilité débutants 80/100
sysprog21/codetrial#318 · 6 commentaires · 2 réactions · 1 personne assignée ·
Les mainteneurs répondent en général sous 1 jour
Toutes les issues de sysprog21/codetrial
Issues similaires
-
Difficulté 2/5 1-3 heures Accessibilité débutants 72/100
Les mainteneurs répondent en général sous 1 jour
-
feat: New firmware supportOuvertefeature
Difficulté 1/5 Moins d'une heure Accessibilité débutants 92/100
dsx-ai-factory/infra-controller#8145 ·
Les mainteneurs répondent en général sous 1 jour
-
bug: workspace access hint suggests a --subject command that fails for hyphen-leading OIDC subjectsOuverte
Difficulté 2/5 1-3 heures Accessibilité débutants 78/100
Les mainteneurs répondent en général sous 1 jour
-
type: bug
Difficulté 2/5 1-3 heures Accessibilité débutants 78/100
Les mainteneurs répondent en général sous 1 jour
-
`last_error_thread_local_then_global` fails when it runs beside the `lumen_event_detail` testOuverteA-FFI C-Testing D-Straightforward S-Ready
Difficulté 2/5 1-3 heures Accessibilité débutants 75/100
Les mainteneurs répondent en général sous 1 jour