diff --git a/doc/install.md b/doc/install.md index dd2bd993..4c49d08e 100644 --- a/doc/install.md +++ b/doc/install.md @@ -1,6 +1,6 @@ ## Install dependency -libCacheSim uses [camke](https://cmake.org/) build system and has a few dependencies: +libCacheSim uses [cmake](https://cmake.org/) build system and has a few dependencies: [glib](https://developer.gnome.org/glib/) [tcmalloc](https://github.com/google/tcmalloc), [zstd](https://github.com/facebook/zstd). @@ -70,4 +70,4 @@ brew install zstd If still shows zstd not found after compilation, try ```bash brew link zstd -``` \ No newline at end of file +``` diff --git a/libCacheSim/bin/cachesim/cache_init.h b/libCacheSim/bin/cachesim/cache_init.h index ea6a2fea..fb520cb2 100644 --- a/libCacheSim/bin/cachesim/cache_init.h +++ b/libCacheSim/bin/cachesim/cache_init.h @@ -1,6 +1,8 @@ #include +#ifndef _GNU_SOURCE #define _GNU_SOURCE +#endif #include #include #include @@ -105,9 +107,19 @@ static inline cache_t *create_cache(const char *trace_path, } else { const char *window_size = strstr(eviction_params, "window-size="); if (window_size == NULL) { - char *new_params = malloc(strlen(eviction_params) + 20); - sprintf(new_params, "%s,window-size=0.01", eviction_params); + // Calculate exact size needed: original + ",window-size=0.01" + null + // terminator + size_t new_params_len = + strlen(eviction_params) + strlen(",window-size=0.01") + 1; + char *new_params = (char *)malloc(new_params_len); + if (new_params == NULL) { + ERROR("failed to allocate memory for new_params\n"); + abort(); + } + snprintf(new_params, new_params_len, "%s,window-size=0.01", + eviction_params); cache = WTinyLFU_init(cc_params, new_params); + free(new_params); // Free the allocated memory } else { cache = WTinyLFU_init(cc_params, eviction_params); }