Distributed File System written in C
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

fix: Fix important bugs highlighted by compiler warnings.

+43 -30
-1
src/createdb.c
··· 5 5 bool touch(const char* fname) { 6 6 FILE* f = fopen(fname, "w"); 7 7 if (f == NULL) { 8 - fclose(f); 9 8 return false; 10 9 } 11 10 fclose(f);
+1 -1
src/lib/block.c
··· 1 1 #include "block.h" 2 2 #include <stdbool.h> 3 - ImplList(Block); 3 + ImplList(Block) 4 4 5 5 Buffer Block_serialize(Block block) { 6 6 Buffer bid_buf = UUID_serialize(block.bid);
+1 -1
src/lib/block.h
··· 17 17 Str cid; 18 18 } Block; 19 19 20 - DefList(Block); 20 + DefList(Block) 21 21 22 22 Buffer Block_serialize(Block block); 23 23
+2 -1
src/lib/dnode.c
··· 1 1 #include "dnode.h" 2 - ImplList(DNode); 2 + ImplList(DNode) 3 3 4 4 Buffer DNode_serialize(DNode dnode) { 5 5 Buffer uuid_buf = UUID_serialize(dnode.nid); ··· 49 49 .buf = buf.buf + len, 50 50 }; 51 51 current = DNode_deserialize(tmp); 52 + exists(current.address); 52 53 out = ListDNode_cons(current, out); 53 54 } 54 55 return ListDNode_reverse(out);
+1 -1
src/lib/dnode.h
··· 19 19 Port port; 20 20 } DNode; 21 21 22 - DefList(DNode); 22 + DefList(DNode) 23 23 24 24 Buffer DNode_serialize(DNode dnode); 25 25
+1 -1
src/lib/inode.c
··· 1 1 #include "inode.h" 2 2 #include "list.h" 3 3 4 - ImplList(INode); 4 + ImplList(INode) 5 5 6 6 Buffer ListINode_serialize(ListINode list) { 7 7 if (list != NULL) return concat(INode_serialize(list->head), ListINode_serialize(list->rest));
+1 -1
src/lib/inode.h
··· 17 17 size_t size; 18 18 } INode; 19 19 20 - DefList(INode); 20 + DefList(INode) 21 21 22 22 Buffer INode_serialize(INode in); 23 23
+3 -3
src/lib/lib.c
··· 15 15 Buffer Buffer_read(FILE* f) { 16 16 exists(f); 17 17 fseek(f, 0, SEEK_END); 18 - size_t len = ftell(f); 18 + size_t len = (size_t)ftell(f); 19 19 fseek(f, 0, SEEK_SET); 20 20 Buffer buf = { 21 21 .buf = calloc(len, sizeof(Byte)), ··· 30 30 return buf; 31 31 } 32 32 33 - void* copy(void* src, size_t nbytes) { 33 + Byte* copy(Byte* src, size_t nbytes) { 34 34 exists(src); 35 - void* out = calloc(nbytes, sizeof(void)); 35 + Byte* out = (Byte*)malloc(nbytes * sizeof(Byte)); 36 36 exists(out); 37 37 memcpy(out, src, nbytes); 38 38 return out;
+1 -1
src/lib/lib.h
··· 39 39 } SafeStr; 40 40 41 41 42 - void* copy(void* src, size_t nbytes); 42 + Byte* copy(Byte* src, size_t nbytes); 43 43 44 44 // Buffer de bytes, lo puedes usar para lo que sea. 45 45 typedef struct {
+13 -4
src/lib/list_str.c
··· 1 1 #include "list_str.h" 2 2 #include "list.h" 3 - ImplList(Str); 3 + ImplList(Str) 4 4 5 5 ListStr split(Str str, char sep) { 6 6 ListStr out = NULL; 7 7 char current[BUF_LEN] = {0}; 8 + size_t cap = strlen(str); 8 9 size_t len = 0; 9 - for (size_t i = 0; i < strlen(str); ++i) { 10 + for (size_t i = 0; i < cap; ++i) { 10 11 if (str[i] == sep) { 11 - out = ListStr_cons(copy(current, len), out); 12 + char* buf = calloc(len + 1, sizeof(char)); 13 + memcpy(buf, current, len); 14 + out = ListStr_cons(buf, out); 12 15 memset(current, 0, len); 13 16 len = 0; 14 17 } else { 18 + if (len + 1 >= BUF_LEN) { 19 + fprintf(stderr, "ERROR: string too long: %s\n", str); 20 + exit(1); 21 + } 15 22 current[len++] = str[i]; 16 23 } 17 24 } 18 - out = ListStr_cons(copy(current, len), out); 25 + char* buf = calloc(len + 1, sizeof(char)); 26 + memcpy(buf, current, len); 27 + out = ListStr_cons(buf, out); 19 28 20 29 return ListStr_reverse(out); 21 30 }
+1 -1
src/lib/list_str.h
··· 4 4 #include "list.h" 5 5 #define BUF_LEN 0x100 6 6 7 - DefList(Str); 7 + DefList(Str) 8 8 9 9 ListStr split(Str str, char sep); 10 10
+13 -9
src/lib/uuid.c
··· 1 1 #include "uuid.h" 2 2 #include <stdbool.h> 3 3 4 - ImplList(HexByte); 4 + ImplList(HexByte) 5 5 6 6 bool UUID_eq(UUID l, UUID r) { 7 7 return l.id1 == r.id1 ··· 37 37 38 38 uint64_t from_hex(Str str, size_t len) { 39 39 uint64_t acc = 0; 40 - for (unsigned int i = 0; i < len; ++i) { 40 + for (size_t i = 0; i < len; ++i) { 41 41 char c = str[i]; 42 42 if ((c <= '9' && c >= '0')) { 43 - acc = acc * 16 + (c - '0'); 43 + acc = acc * 16 + (uint64_t)(c - '0'); 44 44 } else if ((c <= 'F' && c >= 'A')) { 45 - acc = acc * 16 + (c - 'A') + 10; 45 + acc = acc * 16 + (uint64_t)(c - 'A') + 10; 46 46 } else if ((c <= 'f' && c >= 'a')) { 47 - acc = acc * 16 + (c - 'a') + 10; 47 + acc = acc * 16 + (uint64_t)(c - 'a') + 10; 48 48 } else { 49 49 fprintf(stderr, "ERROR: incorrect hex conversion: %s\n", str); 50 50 exit(1); ··· 80 80 fprintf(stderr, "ERROR: sizes are: id1 = %zu, id2 = %zu, id3 = %zu, id4 = %zu, id5 = %zu.\n", strlen(id1), strlen(id2), strlen(id3), strlen(id4), strlen(id5)); 81 81 exit(1); 82 82 } 83 - uint32_t id1i = from_hex(id1, strlen(id1)); 84 - uint16_t id2i = from_hex(id2, strlen(id2)); 85 - uint16_t id3i = from_hex(id3, strlen(id3)); 86 - uint16_t id4i = from_hex(id4, strlen(id4)); 83 + uint32_t id1i = (uint32_t)from_hex(id1, strlen(id1)); 84 + uint16_t id2i = (uint16_t)from_hex(id2, strlen(id2)); 85 + uint16_t id3i = (uint16_t)from_hex(id3, strlen(id3)); 86 + uint16_t id4i = (uint16_t)from_hex(id4, strlen(id4)); 87 87 uint64_t id5i = from_hex(id5, strlen(id5)); 88 + 89 + #pragma GCC diagnostic push 90 + #pragma GCC diagnostic ignored "-Wconversion" 88 91 return (UUID) { 89 92 .id1 = id1i, 90 93 .id2 = id2i, ··· 92 95 .id4 = id4i, 93 96 .id5 = id5i, 94 97 }; 98 + #pragma GCC diagnostic pop 95 99 } 96 100 97 101 HexByte to_hex1(unsigned char c) {
+1 -1
src/lib/uuid.h
··· 18 18 char r; 19 19 } HexByte; 20 20 21 - DefList(HexByte); 21 + DefList(HexByte) 22 22 23 23 Buffer UUID_serialize(UUID in); 24 24
+4 -4
src/testdb.c
··· 101 101 Port port; 102 102 Str chunkid; 103 103 } BlockAssoc; 104 - DefList(BlockAssoc); 105 - ImplList(BlockAssoc); 104 + DefList(BlockAssoc) 105 + ImplList(BlockAssoc) 106 106 bool add_block_to_inode(Str fname, ListBlockAssoc params) { 107 107 if (params != NULL) { 108 108 BlockAssoc p = params->head; ··· 145 145 Port port; 146 146 Block block; 147 147 } BlockLocation; 148 - DefList(BlockLocation); 149 - ImplList(BlockLocation); 148 + DefList(BlockLocation) 149 + ImplList(BlockLocation) 150 150 151 151 typedef struct { 152 152 size_t fsize;