Changeset 2274 in MondoRescue


Ignore:
Timestamp:
Jul 13, 2009, 2:34:28 AM (15 years ago)
Author:
Bruno Cornec
Message:

r3260@localhost: bruno | 2009-07-12 20:27:08 +0200
Replace sprintf by mr_asprintf in newt-specific.c

Location:
branches/2.2.10/mondo/src/common
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • branches/2.2.10/mondo/src/common/libmondo-string.c

    r2242 r2274  
    944944    malloc_string(reason);
    945945    malloc_string(filename);
    946 // out_reason might be null on purpose, so don't bomb if it is :) OK?
     946   
     947    // out_reason might be null on purpose, so don't bomb if it is :) OK?
    947948    assert_string_is_neither_NULL_nor_zerolength(fn);
    948949    if (!strncmp(fn, MNT_RESTORING, strlen(MNT_RESTORING))) {
  • branches/2.2.10/mondo/src/common/newt-specific.c

    r2241 r2274  
    985985
    986986        /*@ buffers ********************************************************** */
    987         char *timeline_str;
     987        char *timeline_str = NULL;
    988988        char *pcline_str = NULL;
    989989        char *taskprogress = NULL;
     
    994994        int j = 0;
    995995
    996         malloc_string(timeline_str);
    997         timeline_str[0] = '\0';
    998 //  log_it("update_eval_call_form called");
    999996        if (num * 100 < denom) {
    1000997            percentage = 1;
     
    10201017            || percentage > g_isoform_old_progress) {
    10211018            g_isoform_old_progress = percentage;
    1022             sprintf(timeline_str,
     1019            mr_asprintf(&timeline_str,
    10231020                    "%2ld:%02ld taken            %2ld:%02ld remaining",
    10241021                    time_taken / 60, time_taken % 60, time_remaining / 60,
     
    10641061                }
    10651062            }
    1066             paranoid_free(pcline_str);
     1063            mr_free(pcline_str);
     1064            mr_free(timeline_str);
    10671065        }
    10681066        if (!g_text_mode) {
     
    10701068            newtRefresh();
    10711069        }
    1072         paranoid_free(timeline_str);
    10731070    }
    10741071
     
    11231120
    11241121        /*@ buffers *************************************************** */
    1125         char *percentline_str;
    1126         char *timeline_str;
     1122        char *percentline_str = NULL;
     1123        char *timeline_str = NULL;
    11271124        char *taskprogress = NULL;
    1128         char *tmp;
    1129 
    1130 //  log_msg(1, "'%s' '%s' '%s'", blurb1, blurb2, blurb3);
    1131         percentline_str = malloc(MAX_NEWT_COMMENT_LEN);
    1132         timeline_str = malloc(MAX_NEWT_COMMENT_LEN);
    1133         malloc_string(tmp);
     1125        char *tmp = NULL;
     1126
    11341127        if (!g_text_mode) {
    11351128            assert(blurb1 != NULL);
     
    11391132        }
    11401133
    1141         percentline_str[0] = '\0';
    1142 
    11431134        current_time = get_time();
    11441135        time_taken = current_time - g_start_time;
     
    11471138        } else {
    11481139            if (g_current_progress > g_maximum_progress) {
    1149                 sprintf(tmp,
     1140                mr_asprintf(&tmp,
    11501141                        "update_progress_form_full(%s,%s,%s) --- g_current_progress=%ld; g_maximum_progress=%ld",
    11511142                        blurb1, blurb2, blurb3, g_current_progress,
    11521143                        g_maximum_progress);
    11531144                log_msg(0, tmp);
     1145                mr_free(tmp);
    11541146                g_current_progress = g_maximum_progress;
    11551147            }
     
    11721164        }
    11731165        g_mysterious_dot_counter = (g_mysterious_dot_counter + 1) % 27;
    1174         sprintf(timeline_str,
    1175                 "%2ld:%02ld taken               %2ld:%02ld remaining  ",
    1176                 time_taken / 60, time_taken % 60, time_remaining / 60,
    1177                 time_remaining % 60);
    1178         sprintf(percentline_str, " %3d%% done                 %3d%% to go",
    1179                 percentage, 100 - percentage);
    1180 
    11811166        if (g_text_mode) {
    11821167            printf("---progress-form---1--- %s\n", blurb1);
     
    12001185            paranoid_free(taskprogress);
    12011186        } else {
     1187            mr_asprintf(&timeline_str,
     1188                "%2ld:%02ld taken               %2ld:%02ld remaining  ",
     1189                time_taken / 60, time_taken % 60, time_remaining / 60,
     1190                time_remaining % 60);
     1191            mr_asprintf(percentline_str, " %3d%% done                 %3d%% to go",
     1192                percentage, 100 - percentage);
     1193
    12021194            center_string(blurb1, 54);
    12031195            center_string(blurb2, 54);
     
    12161208                newtLabelSetText(g_timeline, timeline_str);
    12171209            }
     1210            mr_free(timeline_str);
     1211
    12181212            if (g_percentline) {
    12191213                newtLabelSetText(g_percentline, percentline_str);
    12201214            }
     1215            mr_free(percentline_str);
     1216
    12211217            newtRefresh();
    12221218        }
    1223         paranoid_free(percentline_str);
    1224         paranoid_free(timeline_str);
    1225         paranoid_free(tmp);
    12261219    }
    12271220
     
    15791572
    15801573        /*@ buffers ********************************************************* */
    1581         char *tmp;
    1582         char *differ_sz;
     1574        char *tmp = NULL;
     1575        char *differ_sz = NULL;
    15831576
    15841577        struct s_filelist *filelist;
    1585         malloc_string(reason);
    1586         tmp = malloc(5000);
    1587         malloc_string(differ_sz);
    15881578        assert_string_is_neither_NULL_nor_zerolength(source_file);
    15891579        if (g_text_mode) {
    15901580            log_msg(2, "Text mode. Therefore, no popup list.");
    1591             goto free_to_go;
     1581            return;
    15921582        }
    15931583        log_msg(2, "Examining file %s", source_file);
     
    15961586        if (lng < 1) {
    15971587            log_msg(2, "No lines in file. Therefore, no popup list.");
    1598             paranoid_free(reason);
    1599             goto free_to_go;
     1588            return;
    16001589        } else if (lng >= ARBITRARY_MAXIMUM) {
    16011590            log_msg(2, "Too many files differ for me to list.");
    1602             goto free_to_go;
     1591            return;
    16031592        }
    16041593
     
    16091598
    16101599        if (load_filelist_into_array(filelist, source_file)) {
    1611             log_msg(2, "Can't open %s; therefore, cannot popup list",
    1612                     source_file);
    1613             paranoid_free(reason);
     1600            log_msg(2, "Can't open %s; therefore, cannot popup list", source_file);
    16141601            return;
    16151602        }
     
    16241611                                   keylist[i]);
    16251612        }
    1626         sprintf(differ_sz,
     1613        mr_asprintf(&differ_sz,
    16271614                "  %ld files differ. Hit 'Select' to pick a file. Hit 'Close' to quit the list.",
    16281615                i);
    16291616        newtPushHelpLine(differ_sz);
     1617        mr_free(differ_sz);
     1618
    16301619        bClose = newtCompactButton(10, 15, " Close  ");
    16311620        bSelect = newtCompactButton(30, 15, " Select ");
    1632         sprintf(tmp, "%-10s               %-20s", "Priority", "Filename");
     1621        mr_asprintf(&tmp, "%-10s               %-20s", "Priority", "Filename");
    16331622        headerMsg = newtLabel(2, 1, tmp);
     1623        mr_free(tmp);
     1624
    16341625        newtOpenWindow(5, 4, 70, 16, "Non-matching files");
    16351626        myForm = newtForm(NULL, NULL, 0);
    16361627        newtFormAddComponents(myForm, headerMsg, fileListbox, bClose,
    16371628                              bSelect, NULL);
     1629
     1630        malloc_string(reason);
    16381631        while (!finished) {
    16391632            b_res = newtRunForm(myForm);
     
    16501643                    currline = i;
    16511644                    if (filelist->entries > 0) {
    1652                         severity_of_difference(filelist->el[currline].
    1653                                                filename, reason);
    1654                         sprintf(tmp, "%s --- %s",
    1655                                 filelist->el[currline].filename, reason);
     1645                        severity_of_difference(filelist->el[currline].  filename, reason);
     1646                        mr_asprintf(&tmp, "%s --- %s", filelist->el[currline].filename, reason);
     1647
    16561648                        popup_and_OK(tmp);
     1649                        mr_free(tmp);
    16571650                    }
    16581651                }
    16591652            }
    16601653        }
     1654        paranoid_free(reason);
     1655
    16611656        newtFormDestroy(myForm);
    16621657        newtPopWindow();
    16631658        newtPopHelpLine();
    1664       free_to_go:
    1665         paranoid_free(reason);
    1666         paranoid_free(tmp);
    1667         paranoid_free(differ_sz);
    16681659        return;
    16691660    }
Note: See TracChangeset for help on using the changeset viewer.