Revision 747990ee som/ChunkIDSet/chunkids_ops.c

View differences:

som/ChunkIDSet/chunkids_ops.c
7 7
#include <stdlib.h>
8 8
#include <stdint.h>
9 9
#include <limits.h>
10
#include <string.h>
10 11
#include <assert.h>
11 12

  
12 13
#include "chunkids_private.h"
......
19 20
{
20 21
  struct chunkID_set *p;
21 22
  struct tag *cfg_tags;
22
  int res, type;
23
  int res;
24
  const char *type;
23 25

  
24 26
  p = malloc(sizeof(struct chunkID_set));
25 27
  if (p == NULL) {
......
37 39
    p->elements = NULL;
38 40
  }
39 41
  p->type = CIST_PRIORITY;
40
  res = config_value_int(cfg_tags, "type", &type);
41
  free(cfg_tags);
42
  if (res) {
43
    switch (type) {
44
      case priority:
45
        p->type = CIST_PRIORITY;
46
        break;
47
      case bitmap:
48
        p->type = CIST_BITMAP;
49
        break;
50
      default:
51
        chunkID_set_free(p);
52

  
53
        return NULL; 
42
  type = config_value_str(cfg_tags, "type");
43
  if (type) {
44
    if (!memcmp(type, "priority", strlen(type) - 1)) {
45
      p->type = CIST_PRIORITY;
46
    } else if (!memcmp(type, "bitmap", strlen(type) - 1)) {
47
      p->type = CIST_BITMAP;
48
    } else {
49
      chunkID_set_free(p);
50
      free(cfg_tags);
51

  
52
      return NULL; 
54 53
    }
55 54
  }
55
  free(cfg_tags);
56 56
  assert(p->type == CIST_PRIORITY || p->type == CIST_BITMAP);
57

  
57 58
  return p;
58 59
}
59 60

  

Also available in: Unified diff