Changeset 1074 in MondoRescue for trunk/mondo/src/lib/mr_conf.c


Ignore:
Timestamp:
Jan 25, 2007, 4:18:12 PM (17 years ago)
Author:
Bruno Cornec
Message:

This version of trunk desn't seg fault on mr_msg anymore.
Still not ready for 3.0.0 but improvements ongoing

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/mondo/src/lib/mr_conf.c

    r900 r1074  
    3434#define MRCONF_OPEN_OPENED          0xA
    3535#define MRCONF_CALL_BUT_NOT_OPEN    0xB
     36#define MRCONF_STRING_QUOTE         0xC
    3637
    3738/*setting flags*/
     
    5657#define MRCONF_STR_CLOSE_BUT_NOT_OPEN _("attempt to close mr_conf but it has not been opened yet")
    5758#define MRCONF_STR_CALL_BUT_NOT_OPEN _("attempt to use mr_conf when it has not been opened yet")
     59#define MRCONF_STR_STRING_QUOTE     _("string should be surrounded by quotes")
    5860
    5961/*Flags of internal state*/
     
    6668static size_t mr_conf_filesize(const char *name);
    6769static void mr_conf_error_msg(int error_code, const char *add_line);
    68 static void mr_conf_remove_comments();
     70static void mr_conf_remove_comments(void);
    6971static int mr_conf_check_int_flag(const int flag);
    7072static void mr_conf_set_int_flag(const int flag);
     
    112114
    113115    /*allocate memory for the buffers */
    114     buffer = (char *) malloc(sizeof(char) * (length + 1));
     116    buffer = (char *) mr_malloc(sizeof(char) * (length + 1));
    115117
    116118    if (buffer == NULL) {
     
    139141
    140142/*release all memory and prepare to the next possiable config file*/
    141 void mr_conf_close() {
     143void mr_conf_close(void) {
    142144    /* if not opened => error */
    143145    if (!mr_conf_check_int_flag(MRCONF_INTFLAG_OPEN)) {
     
    233235    mr_asprintf(&q, p);
    234236
     237    if (*p != '"') {
     238        mr_conf_error_msg(MRCONF_STRING_QUOTE, "");
     239        return (NULL);
     240    }
     241    p++;
     242
    235243    /* trunk at first \n */
    236244    r = index(q,'\n');
     245    r--;
     246    if (*r != '"') {
     247        mr_conf_error_msg(MRCONF_STRING_QUOTE, "");
     248        return (NULL);
     249    }
     250    r--;
    237251
    238252    size = r-q+1;
    239253    /*copy filtered data to the buffer */
    240     ret = (char *) malloc(sizeof(char) * (size));
     254    ret = (char *) mr_malloc(sizeof(char) * (size));
    241255    if (ret == NULL) {
    242256        mr_conf_error_msg(MRCONF_ALLOC_FAILED, "");
     
    249263    }
    250264
    251     ret[i] = (char) 0;      /*and set its length */
     265    ret[i] = (char) 0;      /* and set its length */
    252266    mr_free(q);
    253267
     
    278292    }
    279293    /* k is new buffer length now */
    280     tmp_buf = (char *) malloc(sizeof(char) * (k + 1));
     294    tmp_buf = (char *) mr_malloc(sizeof(char) * (k + 1));
    281295    if (tmp_buf == NULL) {
    282296        mr_conf_error_msg(MRCONF_ALLOC_FAILED, "");
     
    371385            break;
    372386
     387        case MRCONF_STRING_QUOTE:
     388            mr_msg(0,"%s %s\n", MRCONF_STR_ERROR, MRCONF_STR_STRING_QUOTE);
     389            break;
     390
    373391        default:
    374392            mr_msg(1,"%s %s\n", MRCONF_STR_ERROR, MRCONF_STR_DEFAULT_ERROR);
Note: See TracChangeset for help on using the changeset viewer.