8000 Revert "Fix format specifiers" by 1a1a11a · Pull Request #199 · 1a1a11a/libCacheSim · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Revert "Fix format specifiers" #199

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 18, 2025
Merged

Conversation

1a1a11a
Copy link
Owner
@1a1a11a 1a1a11a commented Jun 18, 2025

Reverts #188

@1a1a11a 1a1a11a merged commit af4d747 into develop Jun 18, 2025
6 of 8 checks passed
@1a1a11a 1a1a11a deleted the revert-188-fix-format-specifiers branch June 18, 2025 21:23
Copy link

Copy link
@cursor cursor bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Bug: 64-bit Format Specifier Mismatch Bug

The commit introduces a portability bug by replacing PRIu64/PRId64 format specifiers with non-portable %lu/%ld for printing 64-bit integer types (uint64_t, int64_t), and removing the necessary #include <inttypes.h>. This causes format string mismatches and undefined behavior on platforms (e.g., 32-bit systems) where long and unsigned long are 32-bit, leading to incorrect output or data truncation.

libCacheSim/cache/admission/adaptsize/adaptsize_interface.cpp#L3-L93

#include <stdint.h>
#include <sys/types.h>
#include "../../include/libCacheSim/admissionAlgo.h"
#include "adaptsize/adaptsize.h"
#ifdef __cplusplus
extern "C" {
#endif
typedef struct adaptsize_admissioner {
uint64_t max_iteration;
uint64_t reconf_interval;
Adaptsize adaptsize;
} adaptsize_admission_params_t;
static const char *DEFAULT_PARAMS = "max-iteration=15,reconf-interval=30000";
// ***********************************************************************
// **** ****
// **** function declarations ****
// **** ****
// ***********************************************************************
void free_adaptsize_admissioner(admissioner_t *admissioner);
admissioner_t *clone_adaptsize_admissioner(admissioner_t *admissioner);
// declared in admissionAlgo.h
// admissioner_t *create_adaptsize_admissioner(const char *init_params);
void adaptsize_update_stats(admissioner_t *admissioner, const request_t *req,
const uint64_t cache_size);
bool adaptsize_admit(admissioner_t *admissioner, const request_t *req);
// ***********************************************************************
// **** ****
// **** end user facing functions ****
// **** ****
// ***********************************************************************
/**
* @brief This function get called for every lookup to update adaptsize stats
* @param admissioner
* @param req
* @param cache_size current cache size
*/
void adaptsize_update_stats(admissioner_t *admissioner, const request_t *req,
const uint64_t cache_size) {
adaptsize_admission_params_t *pa =
(adaptsize_admission_params_t *)admissioner->params;
pa->adaptsize.updateStats(req, cache_size);
}
/**
* @brief This function used by cache can_admit(), get called everytime an
* object is to be admitted.
* @param pa Adaptsize current data
* @return true cache would be admitted
*/
bool adaptsize_admit(admissioner_t *admissioner, const request_t *req) {
adaptsize_admission_params_t *pa =
(adaptsize_admission_params_t *)admissioner->params;
return pa->adaptsize.admit(req);
}
/**
* @brief Parsing params for adaptsize.
* @param init_params Adaptsize spesific parameter
* @param pa Adaptsize current data
*/
static void adaptsize_admissioner_parse_params(
const char *init_params, adaptsize_admission_params_t *pa) {
if (init_params != NULL) {
char *params_str = strdup(init_params);
char *old_params_str = params_str;
char *end;
while (params_str != NULL && params_str[0] != '\0') {
/* different parameters are separated by comma,
* key and value are separated by = */
char *key = strsep((char **)&params_str, "=");
char *value = strsep((char **)&params_str, ",");
// skip the white space
while (params_str != NULL && *params_str == ' ') {
params_str++;
}
if (strcasecmp(key, "max-iteration") == 0) {
pa->max_iteration = strtoll(value, &end, 10);
} else if (strcasecmp(key, "reconf-interval") == 0) {
pa->reconf_interval = strtoull(value, &end, 10);
} else if (strcasecmp(key, "print") == 0) {
printf("max-iteration=%lu,reconf-interval=%lu", pa->max_iteration,
pa->reconf_interval);

libCacheSim/dataStructure/splay_tuple.c#L53-L277

10000
#include "splay_tuple.h"
// static sTree_tuple * sedgewickized_splay (int i, sTree_tuple * t);
sTree_tuple *splay_t(splay_key_type_t i, sTree_tuple *t) {
/* Simple top down splay, not requiring i to be in the sTree t. */
/* What it does is described above. */
sTree_tuple N, *l, *r, *y;
if (t == NULL) return t;
N.left = N.right = NULL;
l = r = &N;
long l_size = 0, r_size = 0;
for (;;) {
if (key_cmp_t(i, t->key) < 0) {
if (t->left == NULL) break;
if (key_cmp_t(i, t->left->key) < 0) {
y = t->left; /* rotate right */
t->left = y->right;
y->right = t;
t->value = node_value_t(t->left) + node_value_t(t->right) + 1;
t = y;
if (t->left == NULL) break;
}
r->left = t; /* link right */
r = t;
t = t->left;
r_size += 1 + node_value_t(r->right);
} else if (key_cmp_t(i, t->key) > 0) {
if (t->right == NULL) break;
if (key_cmp_t(i, t->right->key) > 0) {
y = t->right; /* rotate left */
t->right = y->left;
y->left = t;
t->value = node_value_t(t->left) + node_value_t(t->right) + 1;
t = y;
if (t->right == NULL) break;
}
l->right = t; /* link left */
l = t;
t = t->right;
l_size += 1 + node_value_t(l->left);
} else {
break;
}
}
// TODO: there should be a better way to do this!!!!!!!!!
l_size += node_value_t(t->left); /* Now l_size and r_size are the sizes of */
r_size += node_value_t(t->right); /* the left and right sTrees we just built.*/
t->value = l_size + r_size + 1;
l->right = r->left = NULL;
/* The following two loops correct the size fields of the right path */
/* from the left child of the root and the right path from the left */
/* child of the root. */
for (y = N.right; y != NULL; y = y->right) {
y->value = l_size;
l_size -= 1 + node_value_t(y->left);
}
for (y = N.left; y != NULL; y = y->left) {
y->value = r_size;
r_size -= 1 + node_value_t(y->right);
}
l->right = t->left; /* assemble */
r->left = t->right;
t->left = N.right;
t->right = N.left;
return t;
}
/* Here is how sedgewick would have written this. */
/* It does the same thing. */
// static sTree_tuple * sedgewickized_splay (int i, sTree_tuple * t) {
// sTree_tuple N, *l, *r, *y;
// if (t == NULL) return t;
// N.left = N.right = NULL;
// l = r = &N;
// for (;;) {
// if (i < t->key) {
// if (t->left != NULL && i < t->left->key) {
// y = t->left; t->left = y->right; y->right = t; t = y;
// }
// if (t->left == NULL) break;
// r->left = t; r = t; t = t->left;
// } else if (i > t->key) {
// if (t->right != NULL && i > t->right->key) {
// y = t->right; t->right = y->left; y->left = t; t = y;
// }
// if (t->right == NULL) break;
// l->right = t; l = t; t = t->right;
// } else break;
// }
// l->right=t->left; r->left=t->right; t->left=N.right; t->right=N.left;
// return t;
// }
sTree_tuple *insert_t(splay_key_type_t i, sTree_tuple *t) {
/* Insert i into the sTree t, unless it's already there. */
/* Return a pointer to the resulting sTree. */
sTree_tuple *new;
new = (sTree_tuple *)malloc(sizeof(sTree_tuple));
if (new == NULL) {
printf("Ran out of space\n");
exit(1);
}
assign_key_t(new, i);
new->value = 1;
if (t == NULL) {
new->left = new->right = NULL;
return new;
}
t = splay_t(i, t);
if (key_cmp_t(i, t->key) < 0 || ((key_cmp_t(i, t->key) == 0) && (i->L < t->key->L))) {
new->left = t->left;
new->right = t;
t->left = NULL;
t->value = 1 + node_value_t(t->right);
} else if (key_cmp_t(i, t->key) > 0 || ((key_cmp_t(i, t->key) == 0) && (i->L > t->key->L))) {
new->right = t->right;
new->left = t;
t->right = NULL;
t->value = 1 + node_value_t(t->left);
} else {
free_node_t(new);
assert(t->value == 1 + node_value_t(t->left) + node_value_t(t->right));
return t;
}
new->value = 1 + node_value_t(new->left) + node_value_t(new->right);
return new;
}
sTree_tuple *splay_delete_t(splay_key_type_t i, sTree_tuple *t) {
if (t == NULL) return NULL;
t = splay_t(i, t);
sTree_tuple *current = t;
sTree_tuple *parent = NULL;
// Iterate until find the node to delete
while (current != NULL) {
if (key_cmp_t(i, current->key) == 0 && i->L == current->key->L) {
sTree_tuple *replacement;
if (current->left == NULL) {
replacement = current->right;
} else if (current->right == NULL) {
replacement = current->left;
} else {
sTree_tuple *successor = current->right;
while (successor->left != NULL) {
successor = successor->left;
}
replacement = splay_t(successor->key, current->right);
replacement->left = current->left;
}
if (parent == NULL) {
t = replacement;
} else if (parent->left == current) {
parent->left = replacement;
} else {
parent->right = replacement;
}
free_node_t(current);
if (t != NULL) {
t->value = node_value_t(t->left) + node_value_t(t->right) + 1;
}
break;
}
parent = current;
if (key_cmp_t(i, current->key) < 0 || (key_cmp_t(i, current->key) == 0 && i->L < current->key->L))
current = current->left;
else
current = current->right;
}
return t;
}
// sTree_tuple *find_node(key_type_t e, sTree_tuple *t) {
// /* Returns a pointer to the node in the sTree with the given value. */
// /* Returns NULL if there is no such node. */
// /* Does not change the sTree. To guarantee logarithmic behavior, */
// /* the node found here should be splayed to the root. */
// T lsize;
//// if ((value < 0) || (value >= node_value_t(t))) return NULL;
// for (;;) {
// if (key_cmp_t(e, t->key)>0){
//
// }
// lsize = node_value_t(t->left);
// if (r < lsize) {
// t = t->left;
// } else if (r > lsize) {
// r = r - lsize -1;
// t = t->right;
// } else {
// return t;
// }
// }
//}
void free_sTree_t(sTree_tuple *t) {
if (t == NULL) return;
free_sTree_t(t->right);
free_sTree_t(t->left);
free_node_t(t);
}
void print_sTree_t(sTree_tuple *t, int d) {
// printf("%p\n",t);
int i;
if (t == NULL) return;
print_sTree_t(t->right, d + 1);
for (i = 0; i < d; i++) printf(" ");
printf("%lu(%ld)\n", t->key->Tmax, t->value);

libCacheSim/bin/MRC/main.c#L45-L46

double miss_ratio_byte = (double)return_value[i].n_miss_byte / (double)return_value[i].n_req_byte;
fprintf(output_file, "%ld,%f, %f\n", cache_size, miss_ratio, miss_ratio_byte);

libCacheSim/bin/debug/aligned.c#L144-L145

printf("uint8_t unaligned read time: %.4f sec\n", time_read_uint8_unaligned);
printf("s: %ld\n", s);

Fix in Cursor


BugBot free trial expires on June 25, 2025
You have used $0.00 of your $20.00 spend limit so far. Manage your spend limit in the Cursor dashboard.

Was this report helpful? Give feedback by reacting with 👍 or 👎

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant
0