Fixed multiple uninitialized memory issues detected by valgrind: 1. SHA256 struct size mismatch: Changed from 64 bytes to 32 bytes to match the actual output of sha256() function (which produces 256 bits = 32 bytes). 2. File tree chunk allocation: Fixed loop that wasn't initializing newly allocated chunks because num_chunks was updated before the initialization loop. Now saves old_num_chunks first. 3. Metadata server process_client_write: Initialized results[i].num_addrs to 0 before use to prevent reading uninitialized value. 4. Address struct initialization: Zero-initialize Address structs before setting fields to ensure the entire union is initialized (union contains either IPv4 or IPv6, leaving unused bytes uninitialized). 5. Fixed bug in IPv6 address creation: Changed incorrect is_ipv4=true to is_ipv4=false for IPv6 addresses. 6. Fixed all_chunk_servers_holding_chunk: Function was incrementing counter for all chunk servers instead of only those containing the hash, causing access to uninitialized array elements. All valgrind errors resolved: ERROR SUMMARY: 0 errors from 0 contexts
33 lines
658 B
C
33 lines
658 B
C
#ifndef BASIC_INCLUDED
|
|
#define BASIC_INCLUDED
|
|
|
|
#include <stdint.h>
|
|
#include <stdbool.h>
|
|
|
|
typedef struct {
|
|
char data[32];
|
|
} SHA256;
|
|
|
|
typedef struct {
|
|
char *ptr;
|
|
int len;
|
|
} string;
|
|
|
|
typedef uint64_t Time;
|
|
#define INVALID_TIME ((Time) -1)
|
|
|
|
#define S(X) ((string) { (X), (int) sizeof(X)-1 })
|
|
|
|
#define MIN(X, Y) ((X) < (Y) ? (X) : (Y))
|
|
|
|
#define UNREACHABLE __builtin_trap();
|
|
|
|
bool streq(string s1, string s2);
|
|
Time get_current_time(void);
|
|
|
|
bool getargb(int argc, char **argv, char *name);
|
|
string getargs(int argc, char **argv, char *name, char *fallback);
|
|
int getargi(int argc, char **argv, char *name, int fallback);
|
|
|
|
#endif // BASIC_INCLUDED
|