Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

heatmap.c SEGV's when stdin is closed (upstream exits 0) #3

Open
mcavage opened this issue Nov 13, 2013 · 0 comments
Open

heatmap.c SEGV's when stdin is closed (upstream exits 0) #3

mcavage opened this issue Nov 13, 2013 · 0 comments

Comments

@mcavage
Copy link

mcavage commented Nov 13, 2013

Take my patch. You know you'll love it:

diff --git a/heatmap.c b/heatmap.c
index 601a240..6f0fc49 100644
--- a/heatmap.c
+++ b/heatmap.c
@@ -1,5 +1,4 @@

-
 #include <stdlib.h>
 #include <stdio.h>
 #include <string.h>
@@ -32,7 +31,7 @@ typedef enum { B_FALSE, B_TRUE } boolean_t;

 #define    LEGEND_WIDTH    10

-#define    BUFFER_SIZE 4096
+#define    BUFFER_SIZE 65535

 #define    TITLE   "T E R M I N A L   H E A T M A P"

@@ -79,6 +78,20 @@ print_title(char *title)
 }

 void
+init_canvas()
+{
+   int i;
+   int j;
+
+   for (i = 0; i < w; i++) {
+       for (j = 0; j< h ; j++) {
+           fprintf(stdout, CSI "%d;4H", j); /* move afore the line */
+           fprintf(stdout, CSI "1P"); /* truncate on the left */
+       }
+   }
+}
+
+void
 print_time_markers(void)
 {
    int offs;
@@ -560,6 +573,7 @@ main(int argc, char **argv)
     * Set up the screen:
     */
    fprintf(stdout, CLRSCR NOCURS);
+   init_canvas();
    print_title(opt_title != NULL ? opt_title : TITLE);
    print_time_markers();

@@ -569,8 +583,13 @@ main(int argc, char **argv)
     * where each integer value will increment the bucket it fits in.
     */
    for (;;) {
-       char *buf = fgets(line_buffer, BUFFER_SIZE, stdin);
-       int *row = line_to_row(buf);
+       char *buf;
+       int *row;
+
+       if ((buf = fgets(line_buffer, BUFFER_SIZE, stdin)) == NULL)
+           exit(0);
+
+       row = line_to_row(buf);

        if (row == NULL) {
            fprintf(stdout, CLRSCR CURS);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant