Changeset 2516 in MondoRescue for branches/2.2.9/mondo/src


Ignore:
Timestamp:
Jan 4, 2010, 7:36:12 PM (14 years ago)
Author:
Bruno Cornec
Message:

r3227@localhost (orig r2261): bruno | 2009-07-12 02:04:25 +0200

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.9/mondo/src/common/libmondo-mountlist.c

    r2394 r2516  
    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        log_it(tmp);
    378390        mr_strcat(flaws_str, "%s", tmp);
    379391        res++;
     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
     
    394408        if (curr_part_no - prev_part_no > 1) {
    395409            if (prev_part_no == 0) {
    396                 sprintf(tmp, " Gap prior to %s.", device);
     410                mr_asprintf(&tmp, " Gap prior to %s.", device);
    397411                log_it(tmp);
    398412                mr_strcat(flaws_str, "%s", tmp);
     413                mr_free(tmp);
    399414                res++;
    400415            } else if (curr_part_no > 5
    401416                       || (curr_part_no <= 4 && prev_part_no > 0)) {
    402                 sprintf(tmp, " Gap on %s between %d and %d.", drive,
     417                mr_asprintf(&tmp, " Gap on %s between %d and %d.", drive,
    403418                        prev_part_no, curr_part_no);
    404419                log_it(tmp);
    405420                mr_strcat(flaws_str, "%s", tmp);
     421                mr_free(tmp);
    406422                res++;
    407423            }
     
    412428        if ((curr_part_no >= 5 && prev_part_no == 4)
    413429            && (strcmp(part_table_fmt, "MBR") == 0)) {
    414             sprintf(tmp, " Partition 4 of %s is occupied.", drive);
     430            mr_asprintf(&tmp, " Partition 4 of %s is occupied.", drive);
    415431            log_it(tmp);
    416432            mr_strcat(flaws_str, "%s", tmp);
     433            mr_free(tmp);
    417434            res++;
    418435        }
     
    425442        }
    426443        if (device_copies > 1) {
    427             sprintf(tmp, " %s %s's.", number_to_text(device_copies),
     444            mr_asprintf(&tmp, " %s %s's.", number_to_text(device_copies),
    428445                    device);
    429446            if (!strstr(flaws_str, tmp)) {
     
    432449                res++;
    433450            }
     451            mr_free(tmp);
    434452        }
    435453        /* silly partition size? */
    436454        if (mountlist->el[pos].size < 8192
    437455            && strcmp(mountlist->el[pos].mountpoint, "lvm")) {
    438             sprintf(tmp, " %s is tiny!", device);
     456            mr_asprintf(&tmp, " %s is tiny!", device);
    439457            log_it(tmp);
    440458            mr_strcat(flaws_str, "%s", tmp);
     459            mr_free(tmp);
    441460            res++;
    442461        }
     
    447466            && strcmp(mountlist->el[pos].mountpoint, "image")
    448467            && mountlist->el[pos].mountpoint[0] != '/') {
    449             sprintf(tmp, " %s has a weird mountpoint.", device);
     468            mr_asprintf(&tmp, " %s has a weird mountpoint.", device);
    450469            log_it(tmp);
    451470            mr_strcat(flaws_str, "%s", tmp);
     471            mr_free(tmp);
    452472            res++;
    453473        }
    454474        /* is format sensible? */
    455475        if (!is_this_a_valid_disk_format(mountlist->el[pos].format)) {
    456             sprintf(tmp, " %s has unsupported format %s.", device, mountlist->el[pos].format);
     476            mr_asprintf(&tmp, " %s has unsupported format %s.", device, mountlist->el[pos].format);
    457477            log_it(tmp);
    458478            mr_strcat(flaws_str, "%s", tmp);
     479            mr_free(tmp);
    459480            res++;
    460481        }
     
    466487    /* Over-allocated the disk? Unallocated space on disk? */
    467488    if (amount_allocated > physical_drive_size + 1) {
    468         sprintf(tmp, " %ld MB over-allocated on %s.",
     489        mr_asprintf(&tmp, " %ld MB over-allocated on %s.",
    469490                amount_allocated - physical_drive_size, drive);
    470491        log_it(tmp);
    471492        mr_strcat(flaws_str, "%s", tmp);
     493        mr_free(tmp);
    472494        res++;
    473495    } else if (amount_allocated < physical_drive_size - 1) {    /* NOT AN ERROR, JUST A WARNING :-) */
    474         sprintf(tmp, " %ld MB unallocated on %s.",
     496        mr_asprintf(&tmp, " %ld MB unallocated on %s.",
    475497                physical_drive_size - amount_allocated, drive);
    476498        log_it(tmp);
    477499        mr_strcat(flaws_str, "%s", tmp);
     500        mr_free(tmp);
    478501    }
    479502
    480503  endoffunc:
    481     paranoid_free(tmp);
    482504    paranoid_free(device);
    483505
Note: See TracChangeset for help on using the changeset viewer.