qstats
qstats copied to clipboard
qstats crashes with no input + Ctrl-D
$ qstats
^D
*** Error in `qstats': double free or corruption (!prev): 0x000055a539c09010 ***
======= Backtrace: =========
/lib/x86_64-linux-gnu/libc.so.6(+0x70bfb)[0x7f160f3abbfb]
[etc]
That's interesting!! I tried it and got:
♥ qstats
^D
Input too small for meaningful summary
I'll try it on a Linux box now
Haha I got Error allocating memory. Will be investigating
Oh I’m on Debian testing x86_64 with glibc 2.24
Nothing seems to happen on my freeBSD macine when qstats is started without any arguments or file.
@jungle-boogie When you start up qstats like that, it interactively takes input (if it doesn't, please let me know) Just type in the numbers (pressing enter in between each one) and when you're done, press Control-D. Does that work? Sorry in advance if I misunderstood what you meant
@tonyfischetti, Doing that works and I don't get a crash:
./qstats
1
2
5
2600
30
Min. 1
1st Qu. 1.5
Median 5
Mean 527.6
3rd Qu. 1315
Max. 2600
Range 2599
Std Dev. 1036.25
Sum 2638
Length 5
But without any input, I do see the error:
% ./qstats
Error allocating memory%
@jungle-boogie Ok, cool! It's supposed to do the interactive thing :) I'm investigating the error with memory allocation today. I wonder why it doesn't happen with the gcc on my Mac 🤔 Maybe I'll try it with different libc s
I can't replicate this :( If this is still an issue, can you let me know and I'll reopen the issue
Changed title to clarify the steps to reproduce: no input followed by Ctrl-D (see original message).
Haha no I mean, I can't reproduce the crash and backtrace when I do that. On all my systems, I either get
♥ qstats
^D
Input too small for meaningful summary
Or
♥ qstats
^D
Error allocating memory
No unhandled crash or backtrace
Found out the Error allocating memory issue. Over in infuncs.c we have:
/* resize to not waste memory */
temp = realloc(build_array, size * sizeof(double));
if(temp == NULL){
free(build_array);
fputs("Error allocating memory", stderr);
exit(EXIT_FAILURE);
}
If there's no input, size will equal 0. The result of allocating 0 is either a unique pointer or just NULL. On systems where this returns NULL, qstats thinks it's an allocation failure.
I'm guessing on @merwok's system, a unique pointer is returned, and somewhere along the line qstats tries writing to it, causing a memory error. The Input too small message happens too far down, after the data_array has already been accessed several times.
I'm guessing a fix would just be to exit early if size is 0.
Also note that my compiler warns about a handful of unused variables. Looking at these and the problem in the previous message may fix my crash!
Cool! I'll get on this! Thanks for the investigation!