Changeset 2261 in MondoRescue


Ignore:
Timestamp:
Jul 12, 2009, 2:04:25 AM (15 years ago)
Author:
Bruno Cornec
Message:

r3202@localhost: bruno | 2009-07-06 18:51:32 +0200

  • Replace sprintf by mr_asprintf in libmondo-mountlist.c
File:
1 edited

Legend:

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

    r2237 r2261  
    5858
    5959    /*@ buffers ******************************************************** */
    60     char tmp[MAX_STR_LEN];
     60    char tmp = NULL;
    6161    char device[MAX_STR_LEN];
    6262    char mountpoint[MAX_STR_LEN];
     
    7373    /*@ initialize ***************************************************** */
    7474    prev_part_no = 0;
    75     tmp[0] = '\0';
    7675    mr_asprintf(&flaws_str, "%s", "");
    7776
     
    8079
    8180    if (physical_drive_size < 0) {
    82         sprintf(tmp, " %s does not exist.", drive);
     81        mr_asprintf(&tmp, " %s does not exist.", drive);
    8382        mr_strcat(flaws_str, "%s", tmp);
    8483    } else {
    85         sprintf(tmp, "%s is %ld MB", drive, physical_drive_size);
     84        mr_asprintf(&tmp, "%s is %ld MB", drive, physical_drive_size);
    8685    }
    8786    log_it(tmp);
     87    mr_free(tmp);
    8888
    8989
     
    104104            /* is it too big? */
    105105            if (curr_part_no > 'h') {
    106                 sprintf(tmp, " Can only have up to 'h' in disklabel.");
     106                mr_asprintf(&tmp, " Can only have up to 'h' in disklabel.");
    107107                log_it(tmp);
    108108                mr_strcat(flaws_str, tmp);
     109                mr_free(tmp);
    109110                res++;
    110111            }
     
    117118            }
    118119            if (device_copies > 1) {
    119                 sprintf(tmp, " %s %s's.", number_to_text(device_copies),
    120                         device);
     120                mr_asprintf(&tmp, " %s %s's.", number_to_text(device_copies), device);
    121121                if (!strstr(flaws_str, tmp)) {
    122122                    log_it(tmp);
     
    124124                    res++;
    125125                }
     126                mr_free(tmp);
    126127            }
    127128            /* silly partition size? */
    128129            if (mountlist->el[pos].size < 8192
    129130                && strcmp(mountlist->el[pos].mountpoint, "lvm")) {
    130                 sprintf(tmp, " %s is tiny!", device);
     131                mr_asprintf(&tmp, " %s is tiny!", device);
    131132                log_it(tmp);
    132133                mr_strcat(flaws_str, tmp);
     134                mr_free(tmp);
    133135                res++;
    134136            }
     
    140142                && strcmp(mountlist->el[pos].mountpoint, "none")
    141143                && mountlist->el[pos].mountpoint[0] != '/') {
    142                 sprintf(tmp, " %s has a weird mountpoint.", device);
     144                mr_asprintf(&tmp, " %s has a weird mountpoint.", device);
    143145                log_it(tmp);
    144146                mr_strcat(flaws_str, tmp);
     147                mr_free(tmp);
    145148                res++;
    146149            }
    147150            /* is format sensible? */
    148151            if (!is_this_a_valid_disk_format(mountlist->el[pos].format)) {
    149                 sprintf(tmp, " %s has unsupported format %s.", device, mountlist->el[pos].format);
     152                mr_asprintf(&tmp, " %s has unsupported format %s.", device, mountlist->el[pos].format);
    150153                log_it(tmp);
    151154                mr_strcat(flaws_str, tmp);
     155                mr_free(tmp);
    152156                res++;
    153157            }
     
    178182            if (curr_part_no - prev_part_no > 1) {
    179183                if (prev_part_no == 0) {
    180                     sprintf(tmp, " Gap prior to %s.", device);
     184                    mr_asprintf(&tmp, " Gap prior to %s.", device);
    181185                    log_it(tmp);
    182186                    mr_strcat(flaws_str, "%s", tmp);
     187                    mr_free(tmp);
    183188                    res++;
    184189                } else if (curr_part_no > 5
    185190                           || (curr_part_no <= 4 && prev_part_no > 0)) {
    186                     sprintf(tmp, " Gap between %ss%d and %d.", drive,
    187                             prev_part_no, curr_part_no);
     191                    mr_asprintf(&tmp, " Gap between %ss%d and %d.", drive, prev_part_no, curr_part_no);
    188192                    log_it(tmp);
    189193                    mr_strcat(flaws_str, "%s", tmp);
     194                    mr_free(tmp);
    190195                    res++;
    191196                }
     
    196201            if ((curr_part_no >= 5 && prev_part_no == 4)
    197202                && (strcmp(part_table_fmt, "MBR") == 0)) {
    198                 sprintf(tmp, " Partition %ss4 is occupied.", drive);
     203                mr_asprintf(&tmp, " Partition %ss4 is occupied.", drive);
    199204                log_it(tmp);
    200205                mr_strcat(flaws_str, "%s", tmp);
     206                mr_free(tmp);
    201207                res++;
    202208            }
     
    209215            }
    210216            if (device_copies > 1) {
    211                 sprintf(tmp, " %s %s's.", number_to_text(device_copies),
    212                         device);
     217                mr_asprintf(&tmp, " %s %s's.", number_to_text(device_copies), device);
    213218                if (!strstr(flaws_str, "%s", tmp)) {
    214219                    log_it(tmp);
     
    216221                    res++;
    217222                }
     223                mr_free(tmp);
    218224            }
    219225            /* silly partition size? */
    220226            if (mountlist->el[pos].size < 8192
    221227                && strcmp(mountlist->el[pos].mountpoint, "lvm")) {
    222                 sprintf(tmp, " %s is tiny!", device);
     228                mr_asprintf(&tmp, " %s is tiny!", device);
    223229                log_it(tmp);
    224230                mr_strcat(flaws_str, "%s", tmp);
     231                mr_free(tmp);
    225232                res++;
    226233            }
     
    232239                && strcmp(mountlist->el[pos].mountpoint, "none")
    233240                && mountlist->el[pos].mountpoint[0] != '/') {
    234                 sprintf(tmp, " %s has a weird mountpoint.", device);
     241                mr_asprintf(&tmp, " %s has a weird mountpoint.", device);
    235242                log_it(tmp);
    236243                mr_strcat(flaws_str, "%s", tmp);
     244                mr_free(tmp);
    237245                res++;
    238246            }
    239247            /* is format sensible? */
    240248            if (!is_this_a_valid_disk_format(mountlist->el[pos].format)) {
    241                 sprintf(tmp, " %s has unsupported format %s.", device, mountlist->el[pos].format);
     249                mr_asprintf(&tmp, " %s has unsupported format %s.", device, mountlist->el[pos].format);
    242250                log_it(tmp);
    243251                mr_strcat(flaws_str, "%s", tmp);
     252                mr_free(tmp);
    244253                res++;
    245254            }
     
    255264                /* is it too big? */
    256265                if (curr_part_no > 'h') {
    257                     sprintf(tmp, " Can only have up to 'h' in disklabel.");
     266                    mr_asprintf(&tmp, " Can only have up to 'h' in disklabel.");
    258267                    log_it(tmp);
    259268                    mr_strcat(flaws_str, "%s", tmp);
     269                    mr_free(tmp);
    260270                    res++;
    261271                }
     
    268278                }
    269279                if (device_copies > 1) {
    270                     sprintf(tmp, " %s %s's.",
    271                             number_to_text(device_copies), device);
     280                    mr_asprintf(&tmp, " %s %s's.", number_to_text(device_copies), device);
    272281                    if (!strstr(flaws_str, tmp)) {
    273282                        log_it(tmp);
     
    275284                        res++;
    276285                    }
     286                    mr_free(tmp);
    277287                }
    278288                /* silly partition size? */
    279289                if (mountlist->el[pos].size < 8192
    280290                    && strcmp(mountlist->el[pos].mountpoint, "lvm")) {
    281                     sprintf(tmp, " %s is tiny!", device);
     291                    mr_asprintf(&tmp, " %s is tiny!", device);
    282292                    log_it(tmp);
    283293                    mr_strcat(flaws_str, "%s", tmp);
     294                    mr_free(tmp);
    284295                    res++;
    285296                }
     
    291302                    && strcmp(mountlist->el[pos].mountpoint, "none")
    292303                    && mountlist->el[pos].mountpoint[0] != '/') {
    293                     sprintf(tmp, " %s has a weird mountpoint.", device);
     304                    mr_asprintf(&tmp, " %s has a weird mountpoint.", device);
    294305                    log_it(tmp);
    295306                    mr_strcat(flaws_str, "%s", tmp);
     307                    mr_free(tmp);
    296308                    res++;
    297309                }
     
    299311                if (!is_this_a_valid_disk_format
    300312                    (mountlist->el[pos].format)) {
    301                     sprintf(tmp, " %s has unsupported format %s.", device, mountlist->el[pos].format);
     313                    mr_asprintf(&tmp, " %s has unsupported format %s.", device, mountlist->el[pos].format);
    302314                    log_it(tmp);
    303315                    mr_strcat(flaws_str, "%s", tmp);
     316                    mr_free(tmp);
    304317                    res++;
    305318                }
     
    317330    if (amount_allocated > physical_drive_size) // Used to be +1, but what if you're 1 MB too high?
    318331    {
    319         sprintf(tmp, " %ld MB over-allocated on %s.",
     332        mr_asprintf(&tmp, " %ld MB over-allocated on %s.",
    320333                amount_allocated - physical_drive_size, drive);
    321334        log_it(tmp);
    322335        mr_strcat(flaws_str, "%s", tmp);
     336        mr_free(tmp);
    323337        res++;
    324338    } else if (amount_allocated < physical_drive_size - 1) {    /* NOT AN ERROR, JUST A WARNING :-) */
    325         sprintf(tmp, " %ld MB unallocated on %s.",
     339        mr_asprintf(&tmp, " %ld MB unallocated on %s.",
    326340                physical_drive_size - amount_allocated, drive);
    327341        log_it(tmp);
    328342        mr_strcat(flaws_str, "%s", tmp);
     343        mr_free(tmp);
    329344    }
    330345    if (res) {
     
    349364
    350365    /*@ buffers ******************************************************** */
    351     char *tmp;
    352     char *device;
     366    char *tmp = NULL;
     367    char *device = NULL;
    353368    char *flaws_str = NULL;
    354369
     
    365380    mr_asprintf(&flaws_str, "%s", "");
    366381
    367     malloc_string(tmp);
    368382    malloc_string(device);
    369383    prev_part_no = 0;
    370     tmp[0] = '\0';
    371 
    372384
    373385    physical_drive_size = get_phys_size_of_drive(drive);
    374386
    375387    if (physical_drive_size < 0) {
    376         sprintf(tmp, " %s does not exist.", drive);
     388        mr_asprintf(&tmp, " %s does not exist.", drive);
    377389        mr_strcat(flaws_str, "%s", tmp);
    378390        res++;
    379391        log_msg(1, tmp);
     392        mr_free(tmp);
    380393        goto endoffunc;
    381394    } else {
    382         sprintf(tmp, "%s is %ld MB", drive, physical_drive_size);
     395        mr_asprintf(&tmp, "%s is %ld MB", drive, physical_drive_size);
    383396        log_it(tmp);
     397        mr_free(tmp);
    384398    }
    385399
     
    393407        if (curr_part_no - prev_part_no > 1) {
    394408            if (prev_part_no == 0) {
    395                 sprintf(tmp, " Gap prior to %s.", device);
     409                mr_asprintf(&tmp, " Gap prior to %s.", device);
    396410                log_it(tmp);
    397411                mr_strcat(flaws_str, "%s", tmp);
     412                mr_free(tmp);
    398413                res++;
    399414            } else if (curr_part_no > 5
    400415                       || (curr_part_no <= 4 && prev_part_no > 0)) {
    401                 sprintf(tmp, " Gap on %s between %d and %d.", drive,
     416                mr_asprintf(&tmp, " Gap on %s between %d and %d.", drive,
    402417                        prev_part_no, curr_part_no);
    403418                log_it(tmp);
    404419                mr_strcat(flaws_str, "%s", tmp);
     420                mr_free(tmp);
    405421                res++;
    406422            }
     
    411427        if ((curr_part_no >= 5 && prev_part_no == 4)
    412428            && (strcmp(part_table_fmt, "MBR") == 0)) {
    413             sprintf(tmp, " Partition 4 of %s is occupied.", drive);
     429            mr_asprintf(&tmp, " Partition 4 of %s is occupied.", drive);
    414430            log_it(tmp);
    415431            mr_strcat(flaws_str, "%s", tmp);
     432            mr_free(tmp);
    416433            res++;
    417434        }
     
    424441        }
    425442        if (device_copies > 1) {
    426             sprintf(tmp, " %s %s's.", number_to_text(device_copies),
     443            mr_asprintf(&tmp, " %s %s's.", number_to_text(device_copies),
    427444                    device);
    428445            if (!strstr(flaws_str, tmp)) {
     
    431448                res++;
    432449            }
     450            mr_free(tmp);
    433451        }
    434452        /* silly partition size? */
    435453        if (mountlist->el[pos].size < 8192
    436454            && strcmp(mountlist->el[pos].mountpoint, "lvm")) {
    437             sprintf(tmp, " %s is tiny!", device);
     455            mr_asprintf(&tmp, " %s is tiny!", device);
    438456            log_it(tmp);
    439457            mr_strcat(flaws_str, "%s", tmp);
     458            mr_free(tmp);
    440459            res++;
    441460        }
     
    446465            && strcmp(mountlist->el[pos].mountpoint, "image")
    447466            && mountlist->el[pos].mountpoint[0] != '/') {
    448             sprintf(tmp, " %s has a weird mountpoint.", device);
     467            mr_asprintf(&tmp, " %s has a weird mountpoint.", device);
    449468            log_it(tmp);
    450469            mr_strcat(flaws_str, "%s", tmp);
     470            mr_free(tmp);
    451471            res++;
    452472        }
    453473        /* is format sensible? */
    454474        if (!is_this_a_valid_disk_format(mountlist->el[pos].format)) {
    455             sprintf(tmp, " %s has unsupported format %s.", device, mountlist->el[pos].format);
     475            mr_asprintf(&tmp, " %s has unsupported format %s.", device, mountlist->el[pos].format);
    456476            log_it(tmp);
    457477            mr_strcat(flaws_str, "%s", tmp);
     478            mr_free(tmp);
    458479            res++;
    459480        }
     
    465486    /* Over-allocated the disk? Unallocated space on disk? */
    466487    if (amount_allocated > physical_drive_size + 1) {
    467         sprintf(tmp, " %ld MB over-allocated on %s.",
     488        mr_asprintf(&tmp, " %ld MB over-allocated on %s.",
    468489                amount_allocated - physical_drive_size, drive);
    469490        log_it(tmp);
    470491        mr_strcat(flaws_str, "%s", tmp);
     492        mr_free(tmp);
    471493        res++;
    472494    } else if (amount_allocated < physical_drive_size - 1) {    /* NOT AN ERROR, JUST A WARNING :-) */
    473         sprintf(tmp, " %ld MB unallocated on %s.",
     495        mr_asprintf(&tmp, " %ld MB unallocated on %s.",
    474496                physical_drive_size - amount_allocated, drive);
    475497        log_it(tmp);
    476498        mr_strcat(flaws_str, "%s", tmp);
     499        mr_free(tmp);
    477500    }
    478501
    479502  endoffunc:
    480     paranoid_free(tmp);
    481503    paranoid_free(device);
    482504
Note: See TracChangeset for help on using the changeset viewer.