mirror of
https://github.com/Karaka-Management/cOMS.git
synced 2026-01-17 21:58:41 +00:00
fix calloc/malloc
This commit is contained in:
parent
7f3fc9a99f
commit
641ff4e4e2
|
|
@ -27,7 +27,7 @@ namespace Image {
|
|||
cv::Size dim = in.size();
|
||||
cv::Mat out(dim, in.type());
|
||||
|
||||
float *intImg = malloc(dim.width * dim.height * sizeof(float));
|
||||
float *intImg = (float *) malloc(dim.width * dim.height * sizeof(float));
|
||||
float sum;
|
||||
|
||||
cv::Vec3b bgr;
|
||||
|
|
|
|||
|
|
@ -50,7 +50,7 @@ namespace Stdlib {
|
|||
|
||||
ht *create_table(void)
|
||||
{
|
||||
ht *table = malloc(sizeof(ht));
|
||||
ht *table = (ht *) malloc(sizeof(ht));
|
||||
if (table == NULL) {
|
||||
return NULL;
|
||||
}
|
||||
|
|
@ -58,7 +58,7 @@ namespace Stdlib {
|
|||
table->size = 0;
|
||||
table->max = 16;
|
||||
|
||||
table->entries = calloc(table->max, sizeof(entry));
|
||||
table->entries = (entry *) calloc(table->max, sizeof(entry));
|
||||
if (table->entries == NULL) {
|
||||
free(table);
|
||||
return NULL;
|
||||
|
|
@ -89,7 +89,7 @@ namespace Stdlib {
|
|||
const char *_set_entry(entry *entries, size_t max, const char *key, void *value, size_t *size)
|
||||
{
|
||||
unsigned long long hash = hash_key(key);
|
||||
size_t index = (size_t)(hash & (unsigned long long)(max - 1));
|
||||
size_t index = (size_t)(hash & (unsigned long long)(max - 1));
|
||||
|
||||
while (entries[index].key != NULL) {
|
||||
if (strcmp(key, entries[index].key) == 0) {
|
||||
|
|
@ -107,7 +107,7 @@ namespace Stdlib {
|
|||
if (size != NULL) {
|
||||
key = strdup(key);
|
||||
if (key == NULL) {
|
||||
return NULL
|
||||
return NULL;
|
||||
}
|
||||
|
||||
++(*size);
|
||||
|
|
@ -126,7 +126,7 @@ namespace Stdlib {
|
|||
return false;
|
||||
}
|
||||
|
||||
entry *new_entries = calloc(new_max, sizeof(entry));
|
||||
entry *new_entries = (entry *) calloc(new_max, sizeof(entry));
|
||||
if (new_entries == NULL) {
|
||||
return false;
|
||||
}
|
||||
|
|
@ -140,7 +140,7 @@ namespace Stdlib {
|
|||
|
||||
free(table->entries);
|
||||
table->entries = new_entries;
|
||||
table->max = new_max;
|
||||
table->max = new_max;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
|
@ -178,7 +178,7 @@ namespace Stdlib {
|
|||
|
||||
if (table->entries[i].key != NULL) {
|
||||
entry tmp = table->entries[i];
|
||||
it->key = tmp.key;
|
||||
it->key = tmp.key;
|
||||
it->value = tmp.value;
|
||||
|
||||
return true;
|
||||
|
|
@ -196,6 +196,8 @@ namespace Stdlib {
|
|||
|
||||
free(table->entries);
|
||||
free(table);
|
||||
|
||||
table = NULL;
|
||||
}
|
||||
};
|
||||
}
|
||||
|
|
|
|||
|
|
@ -46,10 +46,10 @@ namespace Utils {
|
|||
}
|
||||
|
||||
inline
|
||||
void reverse_char(char *arr, int size)
|
||||
void reverse_char(char **arr, int size)
|
||||
{
|
||||
for (int low = 0, high = size - 1; low < high; ++low, --high) {
|
||||
char tmp = arr[low];
|
||||
char* tmp = arr[low];
|
||||
arr[low] = arr[high];
|
||||
arr[high] = tmp;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -27,7 +27,7 @@ namespace Utils {
|
|||
|
||||
for (int i = 0; i < length - 1; ++i) {
|
||||
if (strcmp(id, argv[i]) == 0) {
|
||||
return argv[i + 1];
|
||||
return i + 1 >= length ? NULL : argv[i + 1];
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -95,14 +95,14 @@ namespace Utils {
|
|||
|
||||
FILE *fp = fopen(filename, "rb");
|
||||
if (!fp) {
|
||||
return NULL;
|
||||
return file;
|
||||
}
|
||||
|
||||
fseek(fp, 0, SEEK_END);
|
||||
file.size = ftell(fp);
|
||||
fseek(fp, 0, SEEK_SET);
|
||||
|
||||
file.content = malloc(file.size);
|
||||
file.content = (char *) malloc(file.size);
|
||||
if (!file.content) {
|
||||
fprintf(stderr, "CRITICAL: malloc failed");
|
||||
}
|
||||
|
|
|
|||
|
|
@ -20,12 +20,12 @@ namespace Utils {
|
|||
inline
|
||||
char* generate_string(
|
||||
size_t min = 10, size_t max = 10,
|
||||
char* charset = "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ", int charsetLength = 62
|
||||
char *charset = "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ", int charsetLength = 62
|
||||
) {
|
||||
srand(time(0));
|
||||
|
||||
size_t length = (rand() % (max - min + 1)) + min;
|
||||
char* randomString = malloc(length + 1);
|
||||
char *randomString = (char *) malloc(length + 1);
|
||||
|
||||
for (size_t i = 0; i < length; ++i) {
|
||||
randomString[i] = charset[rand() % charsetLength];
|
||||
|
|
|
|||
|
|
@ -40,10 +40,10 @@ namespace Utils {
|
|||
|
||||
text_diff computeLCSDiff (char **from, int fromSize, char **to, int toSize)
|
||||
{
|
||||
char **diffValues = malloc(fromSize * toSize * sizeof(char *));
|
||||
int *diffMasks = calloc(fromSize * toSize, sizeof(int));
|
||||
char **diffValues = (char **) malloc(fromSize * toSize * sizeof(char *));
|
||||
int *diffMasks = (int *) calloc(fromSize * toSize, sizeof(int));
|
||||
|
||||
int *dm = calloc((fromSize + 1) * (toSize + 1), sizeof(int));
|
||||
int *dm = (int *) calloc((fromSize + 1) * (toSize + 1), sizeof(int));
|
||||
|
||||
if (!diffValues || !diffMasks || !dm) {
|
||||
fprintf(stderr, "CRITICAL: malloc failed");
|
||||
|
|
@ -77,7 +77,7 @@ namespace Utils {
|
|||
|
||||
while (i > 0 || j > 0) {
|
||||
if (j > 0 && dm[i * fromSize + (j - 1)] == dm[i * fromSize + j]) {
|
||||
diffValues[diffIndex] = malloc((strlen(to[j - 1]) + 1) * sizeof(char));
|
||||
diffValues[diffIndex] = (char *) malloc((strlen(to[j - 1]) + 1) * sizeof(char));
|
||||
if (!diffValues[diffIndex]) {
|
||||
fprintf(stderr, "CRITICAL: malloc failed");
|
||||
}
|
||||
|
|
@ -92,7 +92,7 @@ namespace Utils {
|
|||
}
|
||||
|
||||
if (i > 0 && dm[(i - 1) * fromSize + j] == dm[i * fromSize + j]) {
|
||||
diffValues[diffIndex] = malloc((strlen(from[i - 1]) + 1) * sizeof(char));
|
||||
diffValues[diffIndex] = (char *) malloc((strlen(from[i - 1]) + 1) * sizeof(char));
|
||||
if (!diffValues[diffIndex]) {
|
||||
fprintf(stderr, "CRITICAL: malloc failed");
|
||||
}
|
||||
|
|
@ -106,7 +106,7 @@ namespace Utils {
|
|||
continue
|
||||
}
|
||||
|
||||
diffValues[diffIndex] = malloc((strlen(from[i - 1]) + 1) * sizeof(char));
|
||||
diffValues[diffIndex] = (char *) malloc((strlen(from[i - 1]) + 1) * sizeof(char));
|
||||
if (!diffValues[diffIndex]) {
|
||||
fprintf(stderr, "CRITICAL: malloc failed");
|
||||
}
|
||||
|
|
@ -124,8 +124,8 @@ namespace Utils {
|
|||
|
||||
free(dm);
|
||||
|
||||
diffValues = realloc(diffValues, diffIndex * sizeof(char *));
|
||||
diffMasks = realloc(diffMasks, diffIndex * sizeof(int));
|
||||
diffValues = (char **) realloc(diffValues, diffIndex * sizeof(char *));
|
||||
diffMasks = (int *) realloc(diffMasks, diffIndex * sizeof(int));
|
||||
|
||||
if (!diffValues || !diffMasks) {
|
||||
fprintf(stderr, "CRITICAL: malloc failed");
|
||||
|
|
|
|||
|
|
@ -15,22 +15,22 @@
|
|||
|
||||
#ifdef _MSC_VER
|
||||
#define ASSERT_EQUALS(a, b, t1, t2) (\
|
||||
if (a == b) { \
|
||||
if ((a) == (b)) { \
|
||||
printf("."); \
|
||||
} else { \
|
||||
printf("[F]"); \
|
||||
printf("\n\n%s - %i: ", __FILE__, __LINE__); \
|
||||
printf(t1, a); printf(" != "); printf(t2, b); printf("\n"); \
|
||||
printf((t1), (a)); printf(" != "); printf((t2), (b)); printf("\n"); \
|
||||
return 0; } \
|
||||
)
|
||||
|
||||
#define ASSERT_EQUALS_WITH_DELTA(a, b, delta, t1, t2) (\
|
||||
if (oms_abs(a - b) <= _delta) { \
|
||||
if (oms_abs((a) - (b)) <= (delta)) { \
|
||||
printf("."); \
|
||||
} else { \
|
||||
printf("[F]"); \
|
||||
printf("\n\n%s - %i: ", __FILE__, __LINE__); \
|
||||
printf(t1, a); printf(" != "); printf(t2, b); printf("\n"); \
|
||||
printf((t1), (a)); printf(" != "); printf((t2), (b)); printf("\n"); \
|
||||
return 0; } \
|
||||
)
|
||||
#else
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user