Skip to content

Commit 09c7729

Browse files
authored
Added clang-tidy and Fixed Lints (#2)
* Added clang-tidy and fixed lints
1 parent 1c4d72e commit 09c7729

File tree

4 files changed

+38
-3
lines changed

4 files changed

+38
-3
lines changed

.clang-tidy

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
Checks: 'clang-diagnostic-*,clang-analyzer-*,-clang-analyzer-security.insecureAPI.DeprecatedOrUnsafeBufferHandling'
2+
WarningsAsErrors: '*'
3+
FormatStyle: mozilla

.github/workflows/meson.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,9 @@ jobs:
2525
- name: Clang-Format Check
2626
run: make format.check
2727

28+
- name: Clang-Tidy Check
29+
run: make lint.check
30+
2831
- name: Build
2932
run: make build
3033

Makefile

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
.PHONY: init init.release build test format format.check docs docs.deploy clean
1+
.PHONY: init init.release build test format format.check lint lint.check docs docs.deploy clean
22
init:
33
meson setup build --warnlevel=2 --wipe --werror
44

@@ -17,6 +17,12 @@ format:
1717
format.check:
1818
ninja -C build clang-format-check
1919

20+
lint:
21+
ninja -C build clang-tidy-fix
22+
23+
lint.check:
24+
ninja -C build clang-tidy
25+
2026
docs:
2127
doxygen
2228

src/sstable.c

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -161,6 +161,7 @@ SSTable_new(char* path)
161161
size_t file_res = fread(&key_len, sizeof(uint64_t), 1, table->file);
162162
if (file_res != 1) {
163163
perror("fread");
164+
free(table);
164165
return NULL;
165166
}
166167

@@ -169,6 +170,7 @@ SSTable_new(char* path)
169170
file_res = fseeko(table->file, (long long)next, SEEK_CUR);
170171
if (file_res != 0) {
171172
perror("fread");
173+
free(table);
172174
return NULL;
173175
}
174176

@@ -177,30 +179,38 @@ SSTable_new(char* path)
177179
curr_offset += next + sizeof(uint64_t);
178180
}
179181

180-
int seek_res = fseeko(table->file, (long long)table->records[0], SEEK_SET);
182+
int seek_res = fseeko( // NOLINT(clang-analyzer-core.CallAndMessage)
183+
table->file,
184+
(long long)table->records[0],
185+
SEEK_SET);
181186
if (seek_res == -1) {
182187
perror("fseeko");
188+
free(table);
183189
return NULL;
184190
}
185191

186192
uint64_t low_key_len;
187193
size_t file_res = fread(&low_key_len, sizeof(uint64_t), 1, table->file);
188194
if (file_res != 1) {
189195
perror("fread");
196+
free(table);
190197
return NULL;
191198
}
192199

193200
uint64_t val_loc;
194201
file_res = fread(&val_loc, sizeof(int64_t), 1, table->file);
195202
if (file_res != 1) {
196203
perror("fread");
204+
free(table);
197205
return NULL;
198206
}
199207

200208
char* low_key = malloc(low_key_len);
201209
file_res = fread(low_key, sizeof(char), low_key_len, table->file);
202210
if (file_res != low_key_len) {
203211
perror("fread");
212+
free(table);
213+
free(low_key);
204214
return NULL;
205215
}
206216

@@ -211,26 +221,35 @@ SSTable_new(char* path)
211221
fseeko(table->file, (long long)table->records[table->size - 1], SEEK_SET);
212222
if (seek_res == -1) {
213223
perror("fseeko");
224+
free(table);
225+
free(low_key);
214226
return NULL;
215227
}
216228

217229
uint64_t high_key_len;
218230
file_res = fread(&high_key_len, sizeof(uint64_t), 1, table->file);
219231
if (file_res != 1) {
220232
perror("fread");
233+
free(table);
234+
free(low_key);
221235
return NULL;
222236
}
223237

224238
file_res = fread(&val_loc, sizeof(int64_t), 1, table->file);
225239
if (file_res != 1) {
226240
perror("fread");
241+
free(table);
242+
free(low_key);
227243
return NULL;
228244
}
229245

230246
char* high_key = malloc(high_key_len);
231247
file_res = fread(high_key, sizeof(char), high_key_len, table->file);
232248
if (file_res != high_key_len) {
233249
perror("fread");
250+
free(table);
251+
free(low_key);
252+
free(high_key);
234253
return NULL;
235254
}
236255

@@ -308,7 +327,11 @@ SSTable_get_value_loc(struct SSTable* table, char* key, size_t key_len)
308327
int m = a + (b - a) / 2;
309328

310329
struct SSTableRecord record;
311-
SSTableRecord_read(table, &record, table->records[m]);
330+
int res = SSTableRecord_read(table, &record, table->records[m]);
331+
if (res == -1) {
332+
perror("Error reading record from SSTable");
333+
return -1;
334+
}
312335

313336
int cmp = SSTable_key_cmp(&record, key, key_len);
314337
free(record.key);

0 commit comments

Comments
 (0)