rshariffdeen / FixMorph

FixMorph is a morphing tool for C source codes which supports automated code-transfer
https://fixmorph.github.io
MIT License
31 stars 9 forks source link

Unexpected error during evaluating code slices: 'double' #13

Closed RobotSail closed 8 months ago

RobotSail commented 9 months ago

Hi all, I have yet another issue that I ran into when attempting to use the tool.

This issue occurred when attempting to work with the iotop-c project.

Here's the error output that I received from FixMorph:

                        [command]      crochet-diff -ast-dump-json
                                       /dirs/iotop-c-c/src/views.c 2> /
                                       FixMorph/output/test/errors_AST_
                                       dump > /dirs/iotop-
                                       c-c/src/views.c.AST
                        [debug]      return code:0
                        Delete DeclRefExpr(699)

                        Delete MemberExpr(698)

                        Delete MemberExpr(697)

                        Delete TypeLoc(696)

                        Delete CStyleCastExpr(695)

                        Delete DeclRefExpr(694)

                        Delete UnaryOperator(693)

                        Delete CompoundAssignOperator(692)

                        Delete CompoundStmt(682)

                        Delete WhileStmt(671)

                        Replace BinaryOperator(672) with ForStmt(671)

                                analysing for missing function calls
                                analysing for missing macros
                        [command]      cat /dirs/iotop-c-c-
                                       patch//src/views.c | grep
                                       '#ifdef' > /FixMorph/output/test
                                       /tmp/result
                        [command]      clang -E -dD -dM /dirs/iotop-
                                       c-c-patch//src/views.c >
                                       /FixMorph/output/test/tmp/macro-
                                       def
                                analysing for missing variables
                                analysing for missing data-types
                        [ERROR] Crash during evaluate code slices, after 0.009 minutes.
                        [ERROR] Transformation Failed
                        [ERROR] 'double'
                        [ERROR] Unexpected error during evaluate code slices.
                        [ERROR] Runtime Error
                        [ERROR] Error. Exiting...

Here is the patch being backported:

diff --git a/src/views.c b/src/views.c
index 78bc076..8acf39f 100644
--- a/src/views.c
+++ b/src/views.c
@@ -221,12 +221,15 @@ inline void humanize_val(double *value,char *str,int allow_accum) {
        p=1;
        *value/=(double)config.f.base;
    } else {
-       while (*value>config.f.base*config.f.threshold) {
-           if (p+1<strlen(u)) {
-               *value/=(double)config.f.base;
-               p++;
-           } else
-               break;
+       for (; *value > config.f.base * config.f.threshold;) {
+           double baseAsDouble = (double)config.f.base;
+           double newValue = *value / baseAsDouble;
+
+           if (p + 1 < strlen(u)) {
+               p++;
+           } else {
+               break;
+           }
        }
    }

And here is the patch used to generate the downstream version:

diff --git a/src/iotop.h b/src/iotop.h
index 0048a59..ec95b26 100644
--- a/src/iotop.h
+++ b/src/iotop.h
@@ -261,7 +261,7 @@ inline void arr_sort(struct xxxid_stats_arr *pa,int (*cb)(const void *a,const vo

 inline void calc_total(struct xxxid_stats_arr *cs,double *read,double *write);
 inline void calc_a_total(struct act_stats *act,double *read,double *write,double time_s);
-inline void humanize_val(double *value,char *str,int allow_accum);
+inline void turn_into_human_value(double *value,char *str,int allow_accum);
 inline int iotop_sort_cb(const void *a,const void *b);
 inline int create_diff(struct xxxid_stats_arr *cs,struct xxxid_stats_arr *ps,double time_s,uint64_t ts_c,filter_callback_w cb,int width,int *cnt);
 inline int value2scale(double val,double mx);
diff --git a/src/view_batch.c b/src/view_batch.c
index 62dc3b8..408b8c0 100644
--- a/src/view_batch.c
+++ b/src/view_batch.c
@@ -30,10 +30,10 @@ static inline void view_batch(struct xxxid_stats_arr *cs,struct xxxid_stats_arr
    calc_total(cs,&total_read,&total_write);
    calc_a_total(act,&total_a_read,&total_a_write,time_s);

-   humanize_val(&total_read,str_read,1);
-   humanize_val(&total_write,str_write,1);
-   humanize_val(&total_a_read,str_a_read,0);
-   humanize_val(&total_a_write,str_a_write,0);
+   turn_into_human_value(&total_read,str_read,1);
+   turn_into_human_value(&total_write,str_write,1);
+   turn_into_human_value(&total_a_read,str_a_read,0);
+   turn_into_human_value(&total_a_write,str_a_write,0);

    printf(HEADER1_FORMAT,total_read,str_read,"",total_write,str_write,"");

@@ -77,8 +77,8 @@ static inline void view_batch(struct xxxid_stats_arr *cs,struct xxxid_stats_arr
        if (s->exited) // do not show exited processes in batch view
            continue;

-       humanize_val(&read_val,read_str,1);
-       humanize_val(&write_val,write_str,1);
+       turn_into_human_value(&read_val,read_str,1);
+       turn_into_human_value(&write_val,write_str,1);

        pw_name=u8strpadt(s->pw_name,10);

diff --git a/src/view_curses.c b/src/view_curses.c
index c2334e4..96df5b6 100644
--- a/src/view_curses.c
+++ b/src/view_curses.c
@@ -733,10 +733,10 @@ static inline void view_curses(struct xxxid_stats_arr *cs,struct xxxid_stats_arr
        hist_a_w[0]=total_a_write;
    }

-   humanize_val(&total_read,str_read,1);
-   humanize_val(&total_write,str_write,1);
-   humanize_val(&total_a_read,str_a_read,0);
-   humanize_val(&total_a_write,str_a_write,0);
+   turn_into_human_value(&total_read,str_read,1);
+   turn_into_human_value(&total_write,str_write,1);
+   turn_into_human_value(&total_a_read,str_a_read,0);
+   turn_into_human_value(&total_a_write,str_a_write,0);

    gr_width_h=gr_width;
    if (maxy<10||maxx<(int)strlen(HEADER1_FORMAT)+2*(7-5+3-2+(!config.f.hidegraph?gr_width_h+1:0)-2)) {
@@ -1066,8 +1066,8 @@ static inline void view_curses(struct xxxid_stats_arr *cs,struct xxxid_stats_arr
                write_val=s->write_val;
            }

-           humanize_val(&read_val,read_str,1);
-           humanize_val(&write_val,write_str,1);
+           turn_into_human_value(&read_val,read_str,1);
+           turn_into_human_value(&write_val,write_str,1);

            pwt=esc_low_ascii(s->pw_name);
            pw_name=u8strpadt(pwt,9);
diff --git a/src/views.c b/src/views.c
index 78bc076..3927b73 100644
--- a/src/views.c
+++ b/src/views.c
@@ -213,7 +213,7 @@ inline int create_diff(struct xxxid_stats_arr *cs,struct xxxid_stats_arr *ps,dou
    return cs->length;
 }

-inline void humanize_val(double *value,char *str,int allow_accum) {
+inline void turn_into_human_value(double *value,char *str,int allow_accum) {
    const char *u="BKMGTPEZY";
    size_t p=0;
RobotSail commented 9 months ago

Even with a basic patch like this one, I still receive an error:

diff --git a/src/views.c b/src/views.c
index 78bc076..bcb3527 100644
--- a/src/views.c
+++ b/src/views.c
@@ -216,13 +216,14 @@ inline int create_diff(struct xxxid_stats_arr *cs,struct xxxid_stats_arr *ps,dou
 inline void humanize_val(double *value,char *str,int allow_accum) {
    const char *u="BKMGTPEZY";
    size_t p=0;
+   size_t u_length = strlen(u);

    if (config.f.kilobytes) {
        p=1;
        *value/=(double)config.f.base;
    } else {
        while (*value>config.f.base*config.f.threshold) {
-           if (p+1<strlen(u)) {
+           if (p+1<u_length) {
                *value/=(double)config.f.base;
                p++;
            } else

Error:

                                analysing for missing macros
                        [command]      cat /dirs/iotop-c-c-patch//src/views.c |
                                       grep '#ifdef' >
                                       /FixMorph/output/test/tmp/result
                        [command]      clang -E -dD -dM /dirs/iotop-c-c-
                                       patch//src/views.c >
                                       /FixMorph/output/test/tmp/macro-def
                                analysing for missing variables
                                analysing for missing data-types
                        [ERROR] Crash during evaluate code slices, after 0.007 minutes.
                        [ERROR] Transformation Failed
                        [ERROR] 'size_t'
                        [ERROR] Unexpected error during evaluate code slices.
                        [ERROR] Runtime Error
                        [ERROR] Error. Exiting...
rshariffdeen commented 9 months ago

Hi @RobotSail I updated the tool to use latest version of llvm/clang/python I tried your last example, and it worked for me. Can you check if it works for you as well?

RobotSail commented 9 months ago

Thank you so much @rshariffdeen ! I just tried the latest build and was able to get the patch generating correctly :sunglasses: