| 113 | } |
| 114 | |
| 115 | void *make_data(const char source[], size_t *data_size, enum data_type type) |
| 116 | { |
| 117 | switch (type) { |
| 118 | void *data; |
| 119 | bool boolean; |
| 120 | uint64_t uint; |
| 121 | struct mem_range_t file; |
| 122 | bool failed; |
| 123 | |
| 124 | case DATA_TYPE_BOOL: |
| 125 | if (str_eq(source, "true")) { |
| 126 | boolean = true; |
| 127 | } else if (str_eq(source, "false")) { |
| 128 | boolean = false; |
| 129 | } else { |
| 130 | fprintf(stderr, "Invalid boolean value: \"%s\"\n", |
| 131 | source); |
| 132 | return NULL; |
| 133 | } |
| 134 | |
| 135 | *data_size = 1; |
| 136 | data = xmalloc(*data_size); |
| 137 | *(uint8_t *)data = boolean; |
| 138 | return data; |
| 139 | case DATA_TYPE_UINT8: |
| 140 | uint = parse_uint(source, "uint8", UINT8_MAX, &failed); |
| 141 | if (failed) |
| 142 | return NULL; |
| 143 | |
| 144 | *data_size = 1; |
| 145 | data = xmalloc(*data_size); |
| 146 | *(uint8_t *)data = uint; |
| 147 | return data; |
| 148 | case DATA_TYPE_UINT16: |
| 149 | uint = parse_uint(source, "uint16", UINT16_MAX, &failed); |
| 150 | if (failed) |
| 151 | return NULL; |
| 152 | |
| 153 | *data_size = 2; |
| 154 | data = xmalloc(*data_size); |
| 155 | *(uint16_t *)data = uint; |
| 156 | return data; |
| 157 | case DATA_TYPE_UINT32: |
| 158 | uint = parse_uint(source, "uint32", UINT32_MAX, &failed); |
| 159 | if (failed) |
| 160 | return NULL; |
| 161 | |
| 162 | *data_size = 4; |
| 163 | data = xmalloc(*data_size); |
| 164 | *(uint32_t *)data = uint; |
| 165 | return data; |
| 166 | case DATA_TYPE_UINT64: |
| 167 | uint = parse_uint(source, "uint64", UINT64_MAX, &failed); |
| 168 | if (failed) |
| 169 | return NULL; |
| 170 | |
| 171 | *data_size = 8; |
| 172 | data = xmalloc(*data_size); |
no test coverage detected