Skip to content

Commit 17ed363

Browse files
small change for comedyerror for null pointers
1 parent 2e50c08 commit 17ed363

File tree

5 files changed

+31
-31
lines changed

5 files changed

+31
-31
lines changed

code/logic/error.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ const char *fossil_io_what(fossil_status_t error_code) {
4040
switch (error_code) {
4141
// Success and General Errors
4242
case FOSSIL_ERROR_OK: return "No error, operation successful.";
43-
case FOSSIL_ERROR_NULL_POINTER: return "Null pointer encountered.";
43+
case FOSSIL_ERROR_CNULL_POINTER: return "Null pointer encountered.";
4444
case FOSSIL_ERROR_INVALID_ARGUMENT: return "Invalid argument provided.";
4545
case FOSSIL_ERROR_TYPE_MISMATCH: return "Type mismatch encountered.";
4646
case FOSSIL_ERROR_INVALID_OPERATION: return "Invalid operation.";

code/logic/fossil/io/error.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ extern "C" {
2121
typedef enum {
2222
// Success and General Errors
2323
FOSSIL_ERROR_OK = 0,
24-
FOSSIL_ERROR_NULL_POINTER,
24+
FOSSIL_ERROR_CNULL_POINTER,
2525
FOSSIL_ERROR_INVALID_ARGUMENT,
2626
FOSSIL_ERROR_TYPE_MISMATCH,
2727
FOSSIL_ERROR_INVALID_OPERATION,
@@ -200,7 +200,7 @@ namespace fossil {
200200
enum class ErrorCode {
201201
// Success and General Errors
202202
OK = FOSSIL_ERROR_OK,
203-
NULL_POINTER = FOSSIL_ERROR_NULL_POINTER,
203+
NULL_POINTER = FOSSIL_ERROR_CNULL_POINTER,
204204
INVALID_ARGUMENT = FOSSIL_ERROR_INVALID_ARGUMENT,
205205
TYPE_MISMATCH = FOSSIL_ERROR_TYPE_MISMATCH,
206206
INVALID_OPERATION = FOSSIL_ERROR_INVALID_OPERATION,

code/logic/stream.c

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ static const char *fossil_fstream_mode_from_keyword(const char *keyword) {
8787
int32_t fossil_fstream_open(fossil_fstream_t *stream, const char *filename, const char *mode) {
8888
if (stream == NULL || filename == NULL || mode == NULL) {
8989
fprintf(stderr, "Error: Null pointer\n");
90-
return FOSSIL_ERROR_NULL_POINTER;
90+
return FOSSIL_ERROR_CNULL_POINTER;
9191
}
9292

9393
if (strlen(filename) >= FOSSIL_BUFFER_MEDIUM) {
@@ -119,7 +119,7 @@ void fossil_fstream_close(fossil_fstream_t *stream) {
119119
int32_t fossil_fstream_freopen(fossil_fstream_t *stream, const char *filename, const char *mode, FILE *file) {
120120
if (stream == NULL || filename == NULL || mode == NULL || file == NULL) {
121121
fprintf(stderr, "Error: Null pointer\n");
122-
return FOSSIL_ERROR_NULL_POINTER;
122+
return FOSSIL_ERROR_CNULL_POINTER;
123123
}
124124

125125
FILE *new_file = freopen(filename, fossil_fstream_mode_from_keyword(mode), file);
@@ -138,7 +138,7 @@ int32_t fossil_fstream_freopen(fossil_fstream_t *stream, const char *filename, c
138138
size_t fossil_fstream_read(fossil_fstream_t *stream, void *buffer, size_t size, size_t count) {
139139
if (stream == NULL || buffer == NULL || stream->file == NULL) {
140140
fprintf(stderr, "Error: Null pointer\n");
141-
return FOSSIL_ERROR_NULL_POINTER;
141+
return FOSSIL_ERROR_CNULL_POINTER;
142142
}
143143

144144
size_t bytes_read = fread(buffer, size, count, stream->file);
@@ -155,7 +155,7 @@ size_t fossil_fstream_read(fossil_fstream_t *stream, void *buffer, size_t size,
155155
size_t fossil_fstream_write(fossil_fstream_t *stream, const void *buffer, size_t size, size_t count) {
156156
if (stream == NULL || buffer == NULL || stream->file == NULL) {
157157
fprintf(stderr, "Error: Null pointer\n");
158-
return FOSSIL_ERROR_NULL_POINTER;
158+
return FOSSIL_ERROR_CNULL_POINTER;
159159
}
160160

161161
size_t bytes_written = fwrite(buffer, size, count, stream->file);
@@ -172,7 +172,7 @@ size_t fossil_fstream_write(fossil_fstream_t *stream, const void *buffer, size_t
172172
int32_t fossil_fstream_append(fossil_fstream_t *stream, const void * restrict buffer, size_t size, int32_t count) {
173173
if (stream == NULL || buffer == NULL || stream->file == NULL) {
174174
fprintf(stderr, "Error: Null pointer\n");
175-
return FOSSIL_ERROR_NULL_POINTER;
175+
return FOSSIL_ERROR_CNULL_POINTER;
176176
}
177177

178178
fseek(stream->file, 0, SEEK_END);
@@ -190,7 +190,7 @@ int32_t fossil_fstream_append(fossil_fstream_t *stream, const void * restrict bu
190190
int32_t fossil_fstream_seek(fossil_fstream_t *stream, int64_t offset, int32_t origin) {
191191
if (stream == NULL || stream->file == NULL) {
192192
fprintf(stderr, "Error: Null pointer\n");
193-
return FOSSIL_ERROR_NULL_POINTER;
193+
return FOSSIL_ERROR_CNULL_POINTER;
194194
}
195195

196196
int32_t result = fseek(stream->file, offset, origin);
@@ -207,7 +207,7 @@ int32_t fossil_fstream_seek(fossil_fstream_t *stream, int64_t offset, int32_t or
207207
int32_t fossil_fstream_tell(fossil_fstream_t *stream) {
208208
if (stream == NULL || stream->file == NULL) {
209209
fprintf(stderr, "Error: Null pointer\n");
210-
return FOSSIL_ERROR_NULL_POINTER;
210+
return FOSSIL_ERROR_CNULL_POINTER;
211211
}
212212

213213
long position = ftell(stream->file);
@@ -224,7 +224,7 @@ int32_t fossil_fstream_tell(fossil_fstream_t *stream) {
224224
int32_t fossil_fstream_save(fossil_fstream_t *stream, const char *new_filename) {
225225
if (stream == NULL || stream->file == NULL || new_filename == NULL) {
226226
fprintf(stderr, "Error: Null pointer\n");
227-
return FOSSIL_ERROR_NULL_POINTER;
227+
return FOSSIL_ERROR_CNULL_POINTER;
228228
}
229229

230230
if (strlen(new_filename) >= FOSSIL_BUFFER_MEDIUM) {
@@ -236,7 +236,7 @@ int32_t fossil_fstream_save(fossil_fstream_t *stream, const char *new_filename)
236236

237237
if (rename(stream->filename, new_filename) != 0) {
238238
fprintf(stderr, "Error: Failed to save %s\n", new_filename);
239-
return FOSSIL_ERROR_NULL_POINTER;
239+
return FOSSIL_ERROR_CNULL_POINTER;
240240
}
241241

242242
// Reopen the file with the new name
@@ -253,7 +253,7 @@ int32_t fossil_fstream_save(fossil_fstream_t *stream, const char *new_filename)
253253
int32_t fossil_fstream_copy(const char *source_filename, const char *destination_filename) {
254254
if (source_filename == NULL || destination_filename == NULL) {
255255
fprintf(stderr, "Error: Null pointer\n");
256-
return FOSSIL_ERROR_NULL_POINTER;
256+
return FOSSIL_ERROR_CNULL_POINTER;
257257
}
258258

259259
FILE *source_file = fopen(source_filename, "rb");
@@ -291,7 +291,7 @@ int32_t fossil_fstream_copy(const char *source_filename, const char *destination
291291
int32_t fossil_fstream_remove(const char *filename) {
292292
if (filename == NULL) {
293293
fprintf(stderr, "Error: Null pointer\n");
294-
return FOSSIL_ERROR_NULL_POINTER;
294+
return FOSSIL_ERROR_CNULL_POINTER;
295295
}
296296

297297
if (remove(filename) == 0) {
@@ -305,7 +305,7 @@ int32_t fossil_fstream_remove(const char *filename) {
305305
int32_t fossil_fstream_rename(const char *old_filename, const char *new_filename) {
306306
if (old_filename == NULL || new_filename == NULL) {
307307
fprintf(stderr, "Error: Null pointer\n");
308-
return FOSSIL_ERROR_NULL_POINTER;
308+
return FOSSIL_ERROR_CNULL_POINTER;
309309
}
310310

311311
if (rename(old_filename, new_filename) != 0) {
@@ -319,7 +319,7 @@ int32_t fossil_fstream_rename(const char *old_filename, const char *new_filename
319319
int32_t fossil_fstream_flush(fossil_fstream_t *stream) {
320320
if (stream == NULL || stream->file == NULL) {
321321
fprintf(stderr, "Error: Null pointer\n");
322-
return FOSSIL_ERROR_NULL_POINTER;
322+
return FOSSIL_ERROR_CNULL_POINTER;
323323
}
324324

325325
if (fflush(stream->file) != 0) {
@@ -333,7 +333,7 @@ int32_t fossil_fstream_flush(fossil_fstream_t *stream) {
333333
int32_t fossil_fstream_setpos(fossil_fstream_t *stream, int32_t pos) {
334334
if (stream == NULL || stream->file == NULL) {
335335
fprintf(stderr, "Error: Null pointer\n");
336-
return FOSSIL_ERROR_NULL_POINTER;
336+
return FOSSIL_ERROR_CNULL_POINTER;
337337
}
338338

339339
if (fseek(stream->file, pos, SEEK_SET) != 0) {
@@ -347,7 +347,7 @@ int32_t fossil_fstream_setpos(fossil_fstream_t *stream, int32_t pos) {
347347
int32_t fossil_fstream_getpos(fossil_fstream_t *stream, int32_t *pos) {
348348
if (stream == NULL || stream->file == NULL || pos == NULL) {
349349
fprintf(stderr, "Error: Null pointer\n");
350-
return FOSSIL_ERROR_NULL_POINTER;
350+
return FOSSIL_ERROR_CNULL_POINTER;
351351
}
352352

353353
*pos = ftell(stream->file);
@@ -362,7 +362,7 @@ int32_t fossil_fstream_getpos(fossil_fstream_t *stream, int32_t *pos) {
362362
int32_t fossil_fstream_rotate(const char *filename, int32_t n) {
363363
if (filename == NULL) {
364364
fprintf(stderr, "Error: Null pointer\n");
365-
return FOSSIL_ERROR_NULL_POINTER;
365+
return FOSSIL_ERROR_CNULL_POINTER;
366366
}
367367

368368
char old_filename[FOSSIL_BUFFER_MEDIUM];
@@ -389,7 +389,7 @@ int32_t fossil_fstream_rotate(const char *filename, int32_t n) {
389389
int32_t fossil_fstream_backup(const char *filename, const char *backup_suffix) {
390390
if (filename == NULL || backup_suffix == NULL) {
391391
fprintf(stderr, "Error: Null pointer\n");
392-
return FOSSIL_ERROR_NULL_POINTER;
392+
return FOSSIL_ERROR_CNULL_POINTER;
393393
}
394394

395395
char backup_filename[FOSSIL_BUFFER_MEDIUM + 10]; // Length of backup_suffix + maximum integer length
@@ -407,7 +407,7 @@ int32_t fossil_fstream_backup(const char *filename, const char *backup_suffix) {
407407
int32_t fossil_fstream_file_exists(const char *filename) {
408408
if (filename == NULL) {
409409
fprintf(stderr, "Error: Null pointer\n");
410-
return FOSSIL_ERROR_NULL_POINTER;
410+
return FOSSIL_ERROR_CNULL_POINTER;
411411
}
412412

413413
FILE *file = fopen(filename, "r");
@@ -422,7 +422,7 @@ int32_t fossil_fstream_file_exists(const char *filename) {
422422
int32_t fossil_fstream_get_size(fossil_fstream_t *stream) {
423423
if (stream == NULL || stream->file == NULL) {
424424
fprintf(stderr, "Error: Null pointer\n");
425-
return FOSSIL_ERROR_NULL_POINTER;
425+
return FOSSIL_ERROR_CNULL_POINTER;
426426
}
427427

428428
fseek(stream->file, 0, SEEK_END);
@@ -441,7 +441,7 @@ int32_t fossil_fstream_get_size(fossil_fstream_t *stream) {
441441
int32_t fossil_fstream_delete(const char *filename) {
442442
if (filename == NULL) {
443443
fprintf(stderr, "Error: Null pointer\n");
444-
return FOSSIL_ERROR_NULL_POINTER;
444+
return FOSSIL_ERROR_CNULL_POINTER;
445445
}
446446

447447
if (remove(filename) == 0) {

code/tests/cases/test_error.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -48,8 +48,8 @@ FOSSIL_TEST_CASE(c_test_io_what_no_error) {
4848
ASSUME_ITS_EQUAL_CSTR("No error, operation successful.", result);
4949
}
5050

51-
FOSSIL_TEST_CASE(c_test_io_what_null_pointer) {
52-
const char *result = fossil_io_what(FOSSIL_ERROR_NULL_POINTER);
51+
FOSSIL_TEST_CASE(c_test_io_what_CNULL_pointer) {
52+
const char *result = fossil_io_what(FOSSIL_ERROR_CNULL_POINTER);
5353
ASSUME_ITS_EQUAL_CSTR("Null pointer encountered.", result);
5454
}
5555

@@ -204,7 +204,7 @@ FOSSIL_TEST_CASE(c_test_io_what_serialization_failed) {
204204

205205
FOSSIL_TEST_GROUP(c_error_tests) {
206206
FOSSIL_TEST_ADD(c_error_suite, c_test_io_what_no_error);
207-
FOSSIL_TEST_ADD(c_error_suite, c_test_io_what_null_pointer);
207+
FOSSIL_TEST_ADD(c_error_suite, c_test_io_what_CNULL_pointer);
208208
FOSSIL_TEST_ADD(c_error_suite, c_test_io_what_invalid_argument);
209209
FOSSIL_TEST_ADD(c_error_suite, c_test_io_what_type_mismatch);
210210
FOSSIL_TEST_ADD(c_error_suite, c_test_io_what_invalid_operation);

code/tests/cases/test_error.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -48,8 +48,8 @@ FOSSIL_TEST_CASE(cpp_test_io_what_no_error) {
4848
ASSUME_ITS_EQUAL_CSTR("No error, operation successful.", result);
4949
}
5050

51-
FOSSIL_TEST_CASE(cpp_test_io_what_null_pointer) {
52-
const char *result = fossil_io_what(FOSSIL_ERROR_NULL_POINTER);
51+
FOSSIL_TEST_CASE(cpp_test_io_what_CNULL_pointer) {
52+
const char *result = fossil_io_what(FOSSIL_ERROR_CNULL_POINTER);
5353
ASSUME_ITS_EQUAL_CSTR("Null pointer encountered.", result);
5454
}
5555

@@ -207,7 +207,7 @@ FOSSIL_TEST_CASE(cpp_test_io_error_exception_no_error) {
207207
}
208208
}
209209

210-
FOSSIL_TEST_CASE(cpp_test_io_error_exception_null_pointer) {
210+
FOSSIL_TEST_CASE(cpp_test_io_error_exception_CNULL_pointer) {
211211
try {
212212
throw fossil::io::Error(fossil::io::ErrorCode::NULL_POINTER);
213213
} catch (const fossil::io::Error& e) {
@@ -483,7 +483,7 @@ FOSSIL_TEST_CASE(cpp_test_io_error_exception_serialization_failed) {
483483

484484
FOSSIL_TEST_GROUP(cpp_error_tests) {
485485
FOSSIL_TEST_ADD(cpp_error_suite, cpp_test_io_what_no_error);
486-
FOSSIL_TEST_ADD(cpp_error_suite, cpp_test_io_what_null_pointer);
486+
FOSSIL_TEST_ADD(cpp_error_suite, cpp_test_io_what_CNULL_pointer);
487487
FOSSIL_TEST_ADD(cpp_error_suite, cpp_test_io_what_invalid_argument);
488488
FOSSIL_TEST_ADD(cpp_error_suite, cpp_test_io_what_type_mismatch);
489489
FOSSIL_TEST_ADD(cpp_error_suite, cpp_test_io_what_invalid_operation);
@@ -515,7 +515,7 @@ FOSSIL_TEST_GROUP(cpp_error_tests) {
515515
FOSSIL_TEST_ADD(cpp_error_suite, cpp_test_io_what_serialization_failed);
516516

517517
FOSSIL_TEST_ADD(cpp_error_suite, cpp_test_io_error_exception_no_error);
518-
FOSSIL_TEST_ADD(cpp_error_suite, cpp_test_io_error_exception_null_pointer);
518+
FOSSIL_TEST_ADD(cpp_error_suite, cpp_test_io_error_exception_CNULL_pointer);
519519
FOSSIL_TEST_ADD(cpp_error_suite, cpp_test_io_error_exception_invalid_argument);
520520
FOSSIL_TEST_ADD(cpp_error_suite, cpp_test_io_error_exception_type_mismatch);
521521
FOSSIL_TEST_ADD(cpp_error_suite, cpp_test_io_error_exception_invalid_operation);

0 commit comments

Comments
 (0)