Modernize code with clang tidy

This commit is contained in:
Xpl0itU 2022-04-05 20:38:11 +02:00
parent 599775b2ad
commit 407a6d5d1c
13 changed files with 465 additions and 465 deletions

File diff suppressed because it is too large Load Diff

View File

@ -64,12 +64,12 @@
static unsigned char *cJSONUtils_strdup(const unsigned char *const string) {
size_t length = 0;
unsigned char *copy = NULL;
unsigned char *copy = nullptr;
length = strlen((const char *) string) + sizeof("");
copy = (unsigned char *) cJSON_malloc(length);
if (copy == NULL) {
return NULL;
if (copy == nullptr) {
return nullptr;
}
memcpy(copy, string, length);
@ -79,7 +79,7 @@ static unsigned char *cJSONUtils_strdup(const unsigned char *const string) {
/* string comparison which doesn't consider NULL pointers equal */
static int
compare_strings(const unsigned char *string1, const unsigned char *string2, const cJSON_bool case_sensitive) {
if ((string1 == NULL) || (string2 == NULL)) {
if ((string1 == nullptr) || (string2 == nullptr)) {
return 1;
}
@ -110,7 +110,7 @@ static cJSON_bool compare_double(double a, double b) {
/* Compare the next path element of two JSON pointers, two NULL pointers are considered unequal: */
static cJSON_bool
compare_pointers(const unsigned char *name, const unsigned char *pointer, const cJSON_bool case_sensitive) {
if ((name == NULL) || (pointer == NULL)) {
if ((name == nullptr) || (pointer == nullptr)) {
return false;
}
@ -173,10 +173,10 @@ static void encode_string_as_pointer(unsigned char *destination, const unsigned
CJSON_PUBLIC(char *)
cJSONUtils_FindPointerFromObjectTo(const cJSON *const object, const cJSON *const target) {
size_t child_index = 0;
cJSON *current_child = 0;
cJSON *current_child = nullptr;
if ((object == NULL) || (target == NULL)) {
return NULL;
if ((object == nullptr) || (target == nullptr)) {
return nullptr;
}
if (object == target) {
@ -186,10 +186,10 @@ cJSONUtils_FindPointerFromObjectTo(const cJSON *const object, const cJSON *const
/* recursively search all children of the object or array */
for (current_child = object->child;
current_child != NULL; (void) (current_child = current_child->next), child_index++) {
current_child != nullptr; (void) (current_child = current_child->next), child_index++) {
unsigned char *target_pointer = (unsigned char *) cJSONUtils_FindPointerFromObjectTo(current_child, target);
/* found the target? */
if (target_pointer != NULL) {
if (target_pointer != nullptr) {
if (cJSON_IsArray(object)) {
/* reserve enough memory for a 64 bit integer + '/' and '\0' */
unsigned char *full_pointer = (unsigned char *) cJSON_malloc(
@ -200,7 +200,7 @@ cJSONUtils_FindPointerFromObjectTo(const cJSON *const object, const cJSON *const
if (child_index > ULONG_MAX) {
cJSON_free(target_pointer);
cJSON_free(full_pointer);
return NULL;
return nullptr;
}
sprintf((char *) full_pointer, "/%lu%s", (unsigned long) child_index,
target_pointer); /* /<array_index><path> */
@ -224,18 +224,18 @@ cJSONUtils_FindPointerFromObjectTo(const cJSON *const object, const cJSON *const
/* reached leaf of the tree, found nothing */
cJSON_free(target_pointer);
return NULL;
return nullptr;
}
}
/* not found */
return NULL;
return nullptr;
}
/* non broken version of cJSON_GetArrayItem */
static cJSON *get_array_item(const cJSON *array, size_t item) {
cJSON *child = array ? array->child : NULL;
while ((child != NULL) && (item > 0)) {
cJSON *child = array ? array->child : nullptr;
while ((child != nullptr) && (item > 0)) {
item--;
child = child->next;
}
@ -268,30 +268,30 @@ static cJSON_bool decode_array_index_from_pointer(const unsigned char *const poi
static cJSON *get_item_from_pointer(cJSON *const object, const char *pointer, const cJSON_bool case_sensitive) {
cJSON *current_element = object;
if (pointer == NULL) {
return NULL;
if (pointer == nullptr) {
return nullptr;
}
/* follow path of the pointer */
while ((pointer[0] == '/') && (current_element != NULL)) {
while ((pointer[0] == '/') && (current_element != nullptr)) {
pointer++;
if (cJSON_IsArray(current_element)) {
size_t index = 0;
if (!decode_array_index_from_pointer((const unsigned char *) pointer, &index)) {
return NULL;
return nullptr;
}
current_element = get_array_item(current_element, index);
} else if (cJSON_IsObject(current_element)) {
current_element = current_element->child;
/* GetObjectItem. */
while ((current_element != NULL) &&
while ((current_element != nullptr) &&
!compare_pointers((unsigned char *) current_element->string, (const unsigned char *) pointer,
case_sensitive)) {
current_element = current_element->next;
}
} else {
return NULL;
return nullptr;
}
/* skip to the next path token or end of string */
@ -317,7 +317,7 @@ cJSONUtils_GetPointerCaseSensitive(cJSON *const object, const char *pointer) {
static void decode_pointer_inplace(unsigned char *string) {
unsigned char *decoded_string = string;
if (string == NULL) {
if (string == nullptr) {
return;
}
@ -348,7 +348,7 @@ static cJSON *detach_item_from_array(cJSON *array, size_t which) {
}
if (!c) {
/* item doesn't exist */
return NULL;
return nullptr;
}
if (c != array->child) {
/* not the first element */
@ -359,30 +359,30 @@ static cJSON *detach_item_from_array(cJSON *array, size_t which) {
}
if (c == array->child) {
array->child = c->next;
} else if (c->next == NULL) {
} else if (c->next == nullptr) {
array->child->prev = c->prev;
}
/* make sure the detached item doesn't point anywhere anymore */
c->prev = c->next = NULL;
c->prev = c->next = nullptr;
return c;
}
/* detach an item at the given path */
static cJSON *detach_path(cJSON *object, const unsigned char *path, const cJSON_bool case_sensitive) {
unsigned char *parent_pointer = NULL;
unsigned char *child_pointer = NULL;
cJSON *parent = NULL;
cJSON *detached_item = NULL;
unsigned char *parent_pointer = nullptr;
unsigned char *child_pointer = nullptr;
cJSON *parent = nullptr;
cJSON *detached_item = nullptr;
/* copy path and split it in parent and child */
parent_pointer = cJSONUtils_strdup(path);
if (parent_pointer == NULL) {
if (parent_pointer == nullptr) {
goto cleanup;
}
child_pointer = (unsigned char *) strrchr((char *) parent_pointer, '/'); /* last '/' */
if (child_pointer == NULL) {
if (child_pointer == nullptr) {
goto cleanup;
}
/* split strings */
@ -406,7 +406,7 @@ static cJSON *detach_path(cJSON *object, const unsigned char *path, const cJSON_
}
cleanup:
if (parent_pointer != NULL) {
if (parent_pointer != nullptr) {
cJSON_free(parent_pointer);
}
@ -419,56 +419,56 @@ static cJSON *sort_list(cJSON *list, const cJSON_bool case_sensitive) {
cJSON *second = list;
cJSON *current_item = list;
cJSON *result = list;
cJSON *result_tail = NULL;
cJSON *result_tail = nullptr;
if ((list == NULL) || (list->next == NULL)) {
if ((list == nullptr) || (list->next == nullptr)) {
/* One entry is sorted already. */
return result;
}
while ((current_item != NULL) && (current_item->next != NULL) &&
while ((current_item != nullptr) && (current_item->next != nullptr) &&
(compare_strings((unsigned char *) current_item->string, (unsigned char *) current_item->next->string,
case_sensitive) < 0)) {
/* Test for list sorted. */
current_item = current_item->next;
}
if ((current_item == NULL) || (current_item->next == NULL)) {
if ((current_item == nullptr) || (current_item->next == nullptr)) {
/* Leave sorted lists unmodified. */
return result;
}
/* reset pointer to the beginning */
current_item = list;
while (current_item != NULL) {
while (current_item != nullptr) {
/* Walk two pointers to find the middle. */
second = second->next;
current_item = current_item->next;
/* advances current_item two steps at a time */
if (current_item != NULL) {
if (current_item != nullptr) {
current_item = current_item->next;
}
}
if ((second != NULL) && (second->prev != NULL)) {
if ((second != nullptr) && (second->prev != nullptr)) {
/* Split the lists */
second->prev->next = NULL;
second->prev = NULL;
second->prev->next = nullptr;
second->prev = nullptr;
}
/* Recursively sort the sub-lists. */
first = sort_list(first, case_sensitive);
second = sort_list(second, case_sensitive);
result = NULL;
result = nullptr;
/* Merge the sub-lists */
while ((first != NULL) && (second != NULL)) {
cJSON *smaller = NULL;
while ((first != nullptr) && (second != nullptr)) {
cJSON *smaller = nullptr;
if (compare_strings((unsigned char *) first->string, (unsigned char *) second->string, case_sensitive) < 0) {
smaller = first;
} else {
smaller = second;
}
if (result == NULL) {
if (result == nullptr) {
/* start merged list with the smaller element */
result_tail = smaller;
result = smaller;
@ -486,17 +486,17 @@ static cJSON *sort_list(cJSON *list, const cJSON_bool case_sensitive) {
}
}
if (first != NULL) {
if (first != nullptr) {
/* Append rest of first list. */
if (result == NULL) {
if (result == nullptr) {
return first;
}
result_tail->next = first;
first->prev = result_tail;
}
if (second != NULL) {
if (second != nullptr) {
/* Append rest of second list */
if (result == NULL) {
if (result == nullptr) {
return second;
}
result_tail->next = second;
@ -507,14 +507,14 @@ static cJSON *sort_list(cJSON *list, const cJSON_bool case_sensitive) {
}
static void sort_object(cJSON *const object, const cJSON_bool case_sensitive) {
if (object == NULL) {
if (object == nullptr) {
return;
}
object->child = sort_list(object->child, case_sensitive);
}
static cJSON_bool compare_json(cJSON *a, cJSON *b, const cJSON_bool case_sensitive) {
if ((a == NULL) || (b == NULL) || ((a->type & 0xFF) != (b->type & 0xFF))) {
if ((a == nullptr) || (b == nullptr) || ((a->type & 0xFF) != (b->type & 0xFF))) {
/* mismatched type. */
return false;
}
@ -536,7 +536,7 @@ static cJSON_bool compare_json(cJSON *a, cJSON *b, const cJSON_bool case_sensiti
}
case cJSON_Array:
for ((void) (a = a->child), b = b->child; (a != NULL) && (b != NULL); (void) (a = a->next), b = b->next) {
for ((void) (a = a->child), b = b->child; (a != nullptr) && (b != nullptr); (void) (a = a->next), b = b->next) {
cJSON_bool identical = compare_json(a, b, case_sensitive);
if (!identical) {
return false;
@ -544,7 +544,7 @@ static cJSON_bool compare_json(cJSON *a, cJSON *b, const cJSON_bool case_sensiti
}
/* array size mismatch? (one of both children is not NULL) */
if ((a != NULL) || (b != NULL)) {
if ((a != nullptr) || (b != nullptr)) {
return false;
} else {
return true;
@ -553,7 +553,7 @@ static cJSON_bool compare_json(cJSON *a, cJSON *b, const cJSON_bool case_sensiti
case cJSON_Object:
sort_object(a, case_sensitive);
sort_object(b, case_sensitive);
for ((void) (a = a->child), b = b->child; (a != NULL) && (b != NULL); (void) (a = a->next), b = b->next) {
for ((void) (a = a->child), b = b->child; (a != nullptr) && (b != nullptr); (void) (a = a->next), b = b->next) {
cJSON_bool identical = false;
/* compare object keys */
if (compare_strings((unsigned char *) a->string, (unsigned char *) b->string, case_sensitive)) {
@ -567,7 +567,7 @@ static cJSON_bool compare_json(cJSON *a, cJSON *b, const cJSON_bool case_sensiti
}
/* object length mismatch (one of both children is not null) */
if ((a != NULL) || (b != NULL)) {
if ((a != nullptr) || (b != nullptr)) {
return false;
} else {
return true;
@ -592,7 +592,7 @@ static cJSON_bool insert_item_in_array(cJSON *array, size_t which, cJSON *newite
/* item is after the end of the array */
return 0;
}
if (child == NULL) {
if (child == nullptr) {
cJSON_AddItemToArray(array, newitem);
return 1;
}
@ -665,17 +665,17 @@ static enum patch_operation decode_patch_operation(const cJSON *const patch, con
/* overwrite and existing item with another one and free resources on the way */
static void overwrite_item(cJSON *const root, const cJSON replacement) {
if (root == NULL) {
if (root == nullptr) {
return;
}
if (root->string != NULL) {
if (root->string != nullptr) {
cJSON_free(root->string);
}
if (root->valuestring != NULL) {
if (root->valuestring != nullptr) {
cJSON_free(root->valuestring);
}
if (root->child != NULL) {
if (root->child != nullptr) {
cJSON_Delete(root->child);
}
@ -683,12 +683,12 @@ static void overwrite_item(cJSON *const root, const cJSON replacement) {
}
static int apply_patch(cJSON *object, const cJSON *patch, const cJSON_bool case_sensitive) {
cJSON *path = NULL;
cJSON *value = NULL;
cJSON *parent = NULL;
cJSON *path = nullptr;
cJSON *value = nullptr;
cJSON *parent = nullptr;
enum patch_operation opcode = INVALID;
unsigned char *parent_pointer = NULL;
unsigned char *child_pointer = NULL;
unsigned char *parent_pointer = nullptr;
unsigned char *child_pointer = nullptr;
int status = 0;
path = get_object_item(patch, "path", case_sensitive);
@ -712,7 +712,7 @@ static int apply_patch(cJSON *object, const cJSON *patch, const cJSON_bool case_
/* special case for replacing the root */
if (path->valuestring[0] == '\0') {
if (opcode == REMOVE) {
static const cJSON invalid = {NULL, NULL, NULL, cJSON_Invalid, NULL, 0, 0, NULL};
static const cJSON invalid = {nullptr, nullptr, nullptr, cJSON_Invalid, nullptr, 0, 0, nullptr};
overwrite_item(object, invalid);
@ -722,14 +722,14 @@ static int apply_patch(cJSON *object, const cJSON *patch, const cJSON_bool case_
if ((opcode == REPLACE) || (opcode == ADD)) {
value = get_object_item(patch, "value", case_sensitive);
if (value == NULL) {
if (value == nullptr) {
/* missing "value" for add/replace. */
status = 7;
goto cleanup;
}
value = cJSON_Duplicate(value, 1);
if (value == NULL) {
if (value == nullptr) {
/* out of memory for add/replace. */
status = 8;
goto cleanup;
@ -739,12 +739,12 @@ static int apply_patch(cJSON *object, const cJSON *patch, const cJSON_bool case_
/* delete the duplicated value */
cJSON_free(value);
value = NULL;
value = nullptr;
/* the string "value" isn't needed */
if (object->string != NULL) {
if (object->string != nullptr) {
cJSON_free(object->string);
object->string = NULL;
object->string = nullptr;
}
status = 0;
@ -755,7 +755,7 @@ static int apply_patch(cJSON *object, const cJSON *patch, const cJSON_bool case_
if ((opcode == REMOVE) || (opcode == REPLACE)) {
/* Get rid of old. */
cJSON *old_item = detach_path(object, (unsigned char *) path->valuestring, case_sensitive);
if (old_item == NULL) {
if (old_item == nullptr) {
status = 13;
goto cleanup;
}
@ -770,7 +770,7 @@ static int apply_patch(cJSON *object, const cJSON *patch, const cJSON_bool case_
/* Copy/Move uses "from". */
if ((opcode == MOVE) || (opcode == COPY)) {
cJSON *from = get_object_item(patch, "from", case_sensitive);
if (from == NULL) {
if (from == nullptr) {
/* missing "from" for copy/move. */
status = 4;
goto cleanup;
@ -782,7 +782,7 @@ static int apply_patch(cJSON *object, const cJSON *patch, const cJSON_bool case_
if (opcode == COPY) {
value = get_item_from_pointer(object, from->valuestring, case_sensitive);
}
if (value == NULL) {
if (value == nullptr) {
/* missing "from" for copy/move. */
status = 5;
goto cleanup;
@ -790,7 +790,7 @@ static int apply_patch(cJSON *object, const cJSON *patch, const cJSON_bool case_
if (opcode == COPY) {
value = cJSON_Duplicate(value, 1);
}
if (value == NULL) {
if (value == nullptr) {
/* out of memory for copy/move. */
status = 6;
goto cleanup;
@ -798,13 +798,13 @@ static int apply_patch(cJSON *object, const cJSON *patch, const cJSON_bool case_
} else /* Add/Replace uses "value". */
{
value = get_object_item(patch, "value", case_sensitive);
if (value == NULL) {
if (value == nullptr) {
/* missing "value" for add/replace. */
status = 7;
goto cleanup;
}
value = cJSON_Duplicate(value, 1);
if (value == NULL) {
if (value == nullptr) {
/* out of memory for add/replace. */
status = 8;
goto cleanup;
@ -818,7 +818,7 @@ static int apply_patch(cJSON *object, const cJSON *patch, const cJSON_bool case_
if (parent_pointer) {
child_pointer = (unsigned char *) strrchr((char *) parent_pointer, '/');
}
if (child_pointer != NULL) {
if (child_pointer != nullptr) {
child_pointer[0] = '\0';
child_pointer++;
}
@ -826,14 +826,14 @@ static int apply_patch(cJSON *object, const cJSON *patch, const cJSON_bool case_
decode_pointer_inplace(child_pointer);
/* add, remove, replace, move, copy, test. */
if ((parent == NULL) || (child_pointer == NULL)) {
if ((parent == nullptr) || (child_pointer == nullptr)) {
/* Couldn't find object to add to. */
status = 9;
goto cleanup;
} else if (cJSON_IsArray(parent)) {
if (strcmp((char *) child_pointer, "-") == 0) {
cJSON_AddItemToArray(parent, value);
value = NULL;
value = nullptr;
} else {
size_t index = 0;
if (!decode_array_index_from_pointer(child_pointer, &index)) {
@ -845,7 +845,7 @@ static int apply_patch(cJSON *object, const cJSON *patch, const cJSON_bool case_
status = 10;
goto cleanup;
}
value = NULL;
value = nullptr;
}
} else if (cJSON_IsObject(parent)) {
if (case_sensitive) {
@ -854,7 +854,7 @@ static int apply_patch(cJSON *object, const cJSON *patch, const cJSON_bool case_
cJSON_DeleteItemFromObject(parent, (char *) child_pointer);
}
cJSON_AddItemToObject(parent, (char *) child_pointer, value);
value = NULL;
value = nullptr;
} else /* parent is not an object */
{
/* Couldn't find object to add to. */
@ -863,10 +863,10 @@ static int apply_patch(cJSON *object, const cJSON *patch, const cJSON_bool case_
}
cleanup:
if (value != NULL) {
if (value != nullptr) {
cJSON_Delete(value);
}
if (parent_pointer != NULL) {
if (parent_pointer != nullptr) {
cJSON_free(parent_pointer);
}
@ -875,7 +875,7 @@ static int apply_patch(cJSON *object, const cJSON *patch, const cJSON_bool case_
CJSON_PUBLIC(int)
cJSONUtils_ApplyPatches(cJSON *const object, const cJSON *const patches) {
const cJSON *current_patch = NULL;
const cJSON *current_patch = nullptr;
int status = 0;
if (!cJSON_IsArray(patches)) {
@ -883,11 +883,11 @@ cJSONUtils_ApplyPatches(cJSON *const object, const cJSON *const patches) {
return 1;
}
if (patches != NULL) {
if (patches != nullptr) {
current_patch = patches->child;
}
while (current_patch != NULL) {
while (current_patch != nullptr) {
status = apply_patch(object, current_patch, false);
if (status != 0) {
return status;
@ -900,7 +900,7 @@ cJSONUtils_ApplyPatches(cJSON *const object, const cJSON *const patches) {
CJSON_PUBLIC(int)
cJSONUtils_ApplyPatchesCaseSensitive(cJSON *const object, const cJSON *const patches) {
const cJSON *current_patch = NULL;
const cJSON *current_patch = nullptr;
int status = 0;
if (!cJSON_IsArray(patches)) {
@ -908,11 +908,11 @@ cJSONUtils_ApplyPatchesCaseSensitive(cJSON *const object, const cJSON *const pat
return 1;
}
if (patches != NULL) {
if (patches != nullptr) {
current_patch = patches->child;
}
while (current_patch != NULL) {
while (current_patch != nullptr) {
status = apply_patch(object, current_patch, true);
if (status != 0) {
return status;
@ -925,19 +925,19 @@ cJSONUtils_ApplyPatchesCaseSensitive(cJSON *const object, const cJSON *const pat
static void compose_patch(cJSON *const patches, const unsigned char *const operation, const unsigned char *const path,
const unsigned char *suffix, const cJSON *const value) {
cJSON *patch = NULL;
cJSON *patch = nullptr;
if ((patches == NULL) || (operation == NULL) || (path == NULL)) {
if ((patches == nullptr) || (operation == nullptr) || (path == nullptr)) {
return;
}
patch = cJSON_CreateObject();
if (patch == NULL) {
if (patch == nullptr) {
return;
}
cJSON_AddItemToObject(patch, "op", cJSON_CreateString((const char *) operation));
if (suffix == NULL) {
if (suffix == nullptr) {
cJSON_AddItemToObject(patch, "path", cJSON_CreateString((const char *) path));
} else {
size_t suffix_length = pointer_encoded_length(suffix);
@ -951,7 +951,7 @@ static void compose_patch(cJSON *const patches, const unsigned char *const opera
cJSON_free(full_path);
}
if (value != NULL) {
if (value != nullptr) {
cJSON_AddItemToObject(patch, "value", cJSON_Duplicate(value, 1));
}
cJSON_AddItemToArray(patches, patch);
@ -960,30 +960,30 @@ static void compose_patch(cJSON *const patches, const unsigned char *const opera
CJSON_PUBLIC(void)
cJSONUtils_AddPatchToArray(cJSON *const array, const char *const operation, const char *const path,
const cJSON *const value) {
compose_patch(array, (const unsigned char *) operation, (const unsigned char *) path, NULL, value);
compose_patch(array, (const unsigned char *) operation, (const unsigned char *) path, nullptr, value);
}
static void create_patches(cJSON *const patches, const unsigned char *const path, cJSON *const from, cJSON *const to,
const cJSON_bool case_sensitive) {
if ((from == NULL) || (to == NULL)) {
if ((from == nullptr) || (to == nullptr)) {
return;
}
if ((from->type & 0xFF) != (to->type & 0xFF)) {
compose_patch(patches, (const unsigned char *) "replace", path, 0, to);
compose_patch(patches, (const unsigned char *) "replace", path, nullptr, to);
return;
}
switch (from->type & 0xFF) {
case cJSON_Number:
if ((from->valueint != to->valueint) || !compare_double(from->valuedouble, to->valuedouble)) {
compose_patch(patches, (const unsigned char *) "replace", path, NULL, to);
compose_patch(patches, (const unsigned char *) "replace", path, nullptr, to);
}
return;
case cJSON_String:
if (strcmp(from->valuestring, to->valuestring) != 0) {
compose_patch(patches, (const unsigned char *) "replace", path, NULL, to);
compose_patch(patches, (const unsigned char *) "replace", path, nullptr, to);
}
return;
@ -995,8 +995,8 @@ static void create_patches(cJSON *const patches, const unsigned char *const path
strlen((const char *) path) + 20 + sizeof("/")); /* Allow space for 64bit int. log10(2^64) = 20 */
/* generate patches for all array elements that exist in both "from" and "to" */
for (index = 0; (from_child != NULL) && (to_child !=
NULL); (void) (from_child = from_child->next), (void) (to_child = to_child->next), index++) {
for (index = 0; (from_child != nullptr) && (to_child !=
nullptr); (void) (from_child = from_child->next), (void) (to_child = to_child->next), index++) {
/* check if conversion to unsigned long is valid
* This should be eliminated at compile time by dead code elimination
* if size_t is an alias of unsigned long, or if it is bigger */
@ -1010,7 +1010,7 @@ static void create_patches(cJSON *const patches, const unsigned char *const path
}
/* remove leftover elements from 'from' that are not in 'to' */
for (; (from_child != NULL); (void) (from_child = from_child->next)) {
for (; (from_child != nullptr); (void) (from_child = from_child->next)) {
/* check if conversion to unsigned long is valid
* This should be eliminated at compile time by dead code elimination
* if size_t is an alias of unsigned long, or if it is bigger */
@ -1019,10 +1019,10 @@ static void create_patches(cJSON *const patches, const unsigned char *const path
return;
}
sprintf((char *) new_path, "%lu", (unsigned long) index);
compose_patch(patches, (const unsigned char *) "remove", path, new_path, NULL);
compose_patch(patches, (const unsigned char *) "remove", path, new_path, nullptr);
}
/* add new elements in 'to' that were not in 'from' */
for (; (to_child != NULL); (void) (to_child = to_child->next), index++) {
for (; (to_child != nullptr); (void) (to_child = to_child->next), index++) {
compose_patch(patches, (const unsigned char *) "add", path, (const unsigned char *) "-", to_child);
}
cJSON_free(new_path);
@ -1030,19 +1030,19 @@ static void create_patches(cJSON *const patches, const unsigned char *const path
}
case cJSON_Object: {
cJSON *from_child = NULL;
cJSON *to_child = NULL;
cJSON *from_child = nullptr;
cJSON *to_child = nullptr;
sort_object(from, case_sensitive);
sort_object(to, case_sensitive);
from_child = from->child;
to_child = to->child;
/* for all object values in the object with more of them */
while ((from_child != NULL) || (to_child != NULL)) {
while ((from_child != nullptr) || (to_child != nullptr)) {
int diff;
if (from_child == NULL) {
if (from_child == nullptr) {
diff = 1;
} else if (to_child == NULL) {
} else if (to_child == nullptr) {
diff = -1;
} else {
diff = compare_strings((unsigned char *) from_child->string, (unsigned char *) to_child->string,
@ -1068,7 +1068,7 @@ static void create_patches(cJSON *const patches, const unsigned char *const path
} else if (diff < 0) {
/* object element doesn't exist in 'to' --> remove it */
compose_patch(patches, (const unsigned char *) "remove", path, (unsigned char *) from_child->string,
NULL);
nullptr);
from_child = from_child->next;
} else {
@ -1089,10 +1089,10 @@ static void create_patches(cJSON *const patches, const unsigned char *const path
CJSON_PUBLIC(cJSON *)
cJSONUtils_GeneratePatches(cJSON *const from, cJSON *const to) {
cJSON *patches = NULL;
cJSON *patches = nullptr;
if ((from == NULL) || (to == NULL)) {
return NULL;
if ((from == nullptr) || (to == nullptr)) {
return nullptr;
}
patches = cJSON_CreateArray();
@ -1103,10 +1103,10 @@ cJSONUtils_GeneratePatches(cJSON *const from, cJSON *const to) {
CJSON_PUBLIC(cJSON *)
cJSONUtils_GeneratePatchesCaseSensitive(cJSON *const from, cJSON *const to) {
cJSON *patches = NULL;
cJSON *patches = nullptr;
if ((from == NULL) || (to == NULL)) {
return NULL;
if ((from == nullptr) || (to == nullptr)) {
return nullptr;
}
patches = cJSON_CreateArray();
@ -1126,7 +1126,7 @@ cJSONUtils_SortObjectCaseSensitive(cJSON *const object) {
}
static cJSON *merge_patch(cJSON *target, const cJSON *const patch, const cJSON_bool case_sensitive) {
cJSON *patch_child = NULL;
cJSON *patch_child = nullptr;
if (!cJSON_IsObject(patch)) {
/* scalar value, array or NULL, just duplicate */
@ -1140,7 +1140,7 @@ static cJSON *merge_patch(cJSON *target, const cJSON *const patch, const cJSON_b
}
patch_child = patch->child;
while (patch_child != NULL) {
while (patch_child != nullptr) {
if (cJSON_IsNull(patch_child)) {
/* NULL is the indicator to remove a value, see RFC7396 */
if (case_sensitive) {
@ -1149,8 +1149,8 @@ static cJSON *merge_patch(cJSON *target, const cJSON *const patch, const cJSON_b
cJSON_DeleteItemFromObject(target, patch_child->string);
}
} else {
cJSON *replace_me = NULL;
cJSON *replacement = NULL;
cJSON *replace_me = nullptr;
cJSON *replacement = nullptr;
if (case_sensitive) {
replace_me = cJSON_DetachItemFromObjectCaseSensitive(target, patch_child->string);
@ -1159,9 +1159,9 @@ static cJSON *merge_patch(cJSON *target, const cJSON *const patch, const cJSON_b
}
replacement = merge_patch(replace_me, patch_child, case_sensitive);
if (replacement == NULL) {
if (replacement == nullptr) {
cJSON_Delete(target);
return NULL;
return nullptr;
}
cJSON_AddItemToObject(target, patch_child->string, replacement);
@ -1182,10 +1182,10 @@ cJSONUtils_MergePatchCaseSensitive(cJSON *target, const cJSON *const patch) {
}
static cJSON *generate_merge_patch(cJSON *const from, cJSON *const to, const cJSON_bool case_sensitive) {
cJSON *from_child = NULL;
cJSON *to_child = NULL;
cJSON *patch = NULL;
if (to == NULL) {
cJSON *from_child = nullptr;
cJSON *to_child = nullptr;
cJSON *patch = nullptr;
if (to == nullptr) {
/* patch to delete everything */
return cJSON_CreateNull();
}
@ -1199,13 +1199,13 @@ static cJSON *generate_merge_patch(cJSON *const from, cJSON *const to, const cJS
from_child = from->child;
to_child = to->child;
patch = cJSON_CreateObject();
if (patch == NULL) {
return NULL;
if (patch == nullptr) {
return nullptr;
}
while (from_child || to_child) {
int diff;
if (from_child != NULL) {
if (to_child != NULL) {
if (from_child != nullptr) {
if (to_child != nullptr) {
diff = strcmp(from_child->string, to_child->string);
} else {
diff = -1;
@ -1236,10 +1236,10 @@ static cJSON *generate_merge_patch(cJSON *const from, cJSON *const to, const cJS
to_child = to_child->next;
}
}
if (patch->child == NULL) {
if (patch->child == nullptr) {
/* no patch generated */
cJSON_Delete(patch);
return NULL;
return nullptr;
}
return patch;

View File

@ -214,7 +214,7 @@ void drawRGB5A3(int x, int y, float scale, uint8_t *fileContent) {
}
void drawBackgroundDRC(uint32_t w, uint32_t h, uint8_t *out) {
uint32_t *screen2 = NULL;
uint32_t *screen2 = nullptr;
int otherBuff1 = drcBufferSize / 2;
if (cur_buf1) screen2 = (uint32_t *) scrBuffer + tvBufferSize + otherBuff1;

View File

@ -1,8 +1,8 @@
#include "json.h"
char *doit(char *text) {
char *out = NULL;
cJSON *json = NULL;
char *out = nullptr;
cJSON *json = nullptr;
cJSON *str;
json = cJSON_Parse(text);
@ -17,9 +17,9 @@ char *doit(char *text) {
/* Read a file, parse, render back, etc. */
char *dofile(char *filename) {
FILE *f = NULL;
FILE *f = nullptr;
long len = 0;
char *data = NULL;
char *data = nullptr;
/* open in read binary mode */
f = fopen(filename, "rb");
@ -63,11 +63,11 @@ bool setSlotDate(uint32_t highID, uint32_t lowID, uint8_t slot, char *date) {
sprintf(path, "sd:/wiiu/backups/%08x%08x/%u/savemiiMeta.json", highID, lowID, slot);
cJSON *config = cJSON_CreateObject();
if (config == NULL)
if (config == nullptr)
return false;
cJSON *entry = cJSON_CreateString(date);
if (entry == NULL) {
if (entry == nullptr) {
cJSON_Delete(config);
return false;
}
@ -75,11 +75,11 @@ bool setSlotDate(uint32_t highID, uint32_t lowID, uint8_t slot, char *date) {
char *configString = cJSON_Print(config);
cJSON_Delete(config);
if (configString == NULL)
if (configString == nullptr)
return false;
FILE *fp = fopen(path, "wb");
if (fp == NULL)
if (fp == nullptr)
return false;
fwrite(configString, strlen(configString), 1, fp);

View File

@ -1,3 +1,6 @@
#ifndef _JSON_H
#define _JSON_H
#include "cJSON.h"
#include <stdbool.h>
#include <stdio.h>
@ -6,4 +9,6 @@
char *getSlotDate(uint32_t highID, uint32_t lowID, uint8_t slot);
bool setSlotDate(uint32_t highID, uint32_t lowID, uint8_t slot, char *date);
bool setSlotDate(uint32_t highID, uint32_t lowID, uint8_t slot, char *date);
#endif

View File

@ -11,14 +11,14 @@ char renderedBuffer[NUM_LINES][LINE_LENGTH];
bool freetypeHasForeground = false;
uint8_t *frameBufferTVFrontPtr = NULL;
uint8_t *frameBufferTVBackPtr = NULL;
uint8_t *frameBufferTVFrontPtr = nullptr;
uint8_t *frameBufferTVBackPtr = nullptr;
uint32_t frameBufferTVSize = 0;
uint8_t *frameBufferDRCFrontPtr = NULL;
uint8_t *frameBufferDRCBackPtr = NULL;
uint8_t *frameBufferDRCFrontPtr = nullptr;
uint8_t *frameBufferDRCBackPtr = nullptr;
uint32_t frameBufferDRCSize = 0;
uint8_t *currTVFrameBuffer = NULL;
uint8_t *currDRCFrameBuffer = NULL;
uint8_t *currTVFrameBuffer = nullptr;
uint8_t *currDRCFrameBuffer = nullptr;
RGBAColor ttfColor = {0xFFFFFFFF};
uint32_t fontColor = 0xFFFFFFFF;

View File

@ -1,3 +1,6 @@
#ifndef _LOG_FREETYPE_H
#define _LOG_FREETYPE_H
#include <stdbool.h>
#include <stdint.h>
#include <string.h>
@ -29,3 +32,5 @@ void ttfFontColor32(uint32_t color);
void ttfFontColor(uint8_t r, uint8_t g, uint8_t b, uint8_t a);
void WHBLogFreetypeDraw();
#endif

View File

@ -1,12 +1,9 @@
#include "string.hpp"
extern "C" {
#include "icon.h"
#include "json.h"
#include "log_freetype.h"
#include "main.h"
#include "savemng.h"
}
using namespace std;
@ -17,7 +14,7 @@ using namespace std;
uint8_t slot = 0;
int8_t allusers = -1, allusers_d = -1, sdusers = -1;
bool common = 1;
bool common = true;
int menu = 0, mode = 0, task = 0, targ = 0, tsort = 1, sorta = 1;
int cursor = 0, scroll = 0;
int cursorb = 0, cursort = 0, scrollb = 0;
@ -75,14 +72,14 @@ Title *loadWiiUTitles(int run) {
receivedCount = count;
MCP_TitleList(mcp_handle, &receivedCount, (MCPTitleListType *) tList, listSize);
MCP_Close(mcp_handle);
return NULL;
return nullptr;
}
int usable = receivedCount, j = 0;
Saves *savesl = (Saves *) malloc(receivedCount * sizeof(Saves));
if (!savesl) {
promptError("Out of memory.");
return NULL;
return nullptr;
}
for (uint32_t i = 0; i < receivedCount; i++) {
char *element = tList + (i * 0x61);
@ -104,9 +101,9 @@ Title *loadWiiUTitles(int run) {
char path[255];
sprintf(path, "%s:/usr/save/%s", (i == 0) ? "usb" : "mlc", highIDs[a]);
DIR *dir = opendir(path);
if (dir != NULL) {
if (dir != nullptr) {
struct dirent *data;
while ((data = readdir(dir)) != NULL) {
while ((data = readdir(dir)) != nullptr) {
if (data->d_name[0] == '.')
continue;
@ -117,7 +114,7 @@ Title *loadWiiUTitles(int run) {
if (checkEntry(path) == 1) {
for (int i = 0; i < usable; i++) {
if ((savesl[i].highID == (0x00050000 | 0x00050002)) &&
(strtoul(data->d_name, NULL, 16) == savesl[i].lowID)) {
(strtoul(data->d_name, nullptr, 16) == savesl[i].lowID)) {
savesl[i].found = true;
tNoSave--;
break;
@ -136,7 +133,7 @@ Title *loadWiiUTitles(int run) {
Saves *saves = (Saves *) malloc((foundCount + tNoSave) * sizeof(Saves));
if (!saves) {
promptError("Out of memory.");
return NULL;
return nullptr;
}
for (uint8_t a = 0; a < 2; a++) {
@ -144,9 +141,9 @@ Title *loadWiiUTitles(int run) {
char path[255];
sprintf(path, "%s:/usr/save/%s", (i == 0) ? "usb" : "mlc", highIDs[a]);
DIR *dir = opendir(path);
if (dir != NULL) {
if (dir != nullptr) {
struct dirent *data;
while ((data = readdir(dir)) != NULL) {
while ((data = readdir(dir)) != nullptr) {
if (data->d_name[0] == '.')
continue;
@ -154,7 +151,7 @@ Title *loadWiiUTitles(int run) {
data->d_name);
if (checkEntry(path) == 1) {
saves[pos].highID = highIDsNumeric[a];
saves[pos].lowID = strtoul(data->d_name, NULL, 16);
saves[pos].lowID = strtoul(data->d_name, nullptr, 16);
saves[pos].dev = i;
saves[pos].found = false;
pos++;
@ -178,7 +175,7 @@ Title *loadWiiUTitles(int run) {
Title *titles = (Title *) malloc(foundCount * sizeof(Title));
if (!titles) {
promptError("Out of memory.");
return NULL;
return nullptr;
}
for (int i = 0; i < foundCount; i++) {
@ -190,7 +187,7 @@ Title *loadWiiUTitles(int run) {
saves[i].found ? "title" : "save", highID, lowID);
titles[titleswiiu].saveInit = !saves[i].found;
char *xmlBuf = NULL;
char *xmlBuf = nullptr;
if (loadFile(path, (uint8_t * *) & xmlBuf) > 0) {
char *cptr = strchr(strstr(xmlBuf, "product_code"), '>') + 7;
memset(titles[titleswiiu].productCode, 0, sizeof(titles[titleswiiu].productCode));
@ -225,7 +222,7 @@ Title *loadWiiUTitles(int run) {
titles[titleswiiu].lowID = lowID;
titles[titleswiiu].isTitleOnUSB = isTitleOnUSB;
titles[titleswiiu].listID = titleswiiu;
if (loadTitleIcon(&titles[titleswiiu]) < 0) titles[titleswiiu].iconBuf = NULL;
if (loadTitleIcon(&titles[titleswiiu]) < 0) titles[titleswiiu].iconBuf = nullptr;
titleswiiu++;
OSScreenClearBufferEx(SCREEN_TV, 0);
@ -259,12 +256,12 @@ Title *loadWiiTitles() {
for (int k = 0; k < 3; k++) {
sprintf(pathW, "slc:/title/%s", highIDs[k]);
DIR *dir = opendir(pathW);
if (dir != NULL) {
if (dir != nullptr) {
struct dirent *data;
while ((data = readdir(dir)) != NULL) {
while ((data = readdir(dir)) != nullptr) {
for (int ii = 0; ii < 7; ii++) {
if (blacklist[ii][0] == strtoul(highIDs[k], NULL, 16)) {
if (blacklist[ii][1] == strtoul(data->d_name, NULL, 16)) {
if (blacklist[ii][0] == strtoul(highIDs[k], nullptr, 16)) {
if (blacklist[ii][1] == strtoul(data->d_name, nullptr, 16)) {
found = true;
break;
}
@ -280,24 +277,24 @@ Title *loadWiiTitles() {
closedir(dir);
}
}
if (titlesvwii == 0) return NULL;
if (titlesvwii == 0) return nullptr;
Title *titles = (Title *) malloc(titlesvwii * sizeof(Title));
if (!titles) {
promptError("Out of memory.");
return NULL;
return nullptr;
}
int i = 0;
for (int k = 0; k < 3; k++) {
sprintf(pathW, "slc:/title/%s", highIDs[k]);
DIR *dir = opendir(pathW);
if (dir != NULL) {
if (dir != nullptr) {
struct dirent *data;
while ((data = readdir(dir)) != NULL) {
while ((data = readdir(dir)) != nullptr) {
for (int ii = 0; ii < 7; ii++) {
if (blacklist[ii][0] == strtoul(highIDs[k], NULL, 16)) {
if (blacklist[ii][1] == strtoul(data->d_name, NULL, 16)) {
if (blacklist[ii][0] == strtoul(highIDs[k], nullptr, 16)) {
if (blacklist[ii][1] == strtoul(data->d_name, nullptr, 16)) {
found = true;
break;
}
@ -311,7 +308,7 @@ Title *loadWiiTitles() {
char path[256];
sprintf(path, "slc:/title/%s/%s/data/banner.bin", highIDs[k], data->d_name);
FILE *file = fopen(path, "rb");
if (file != NULL) {
if (file != nullptr) {
fseek(file, 0x20, SEEK_SET);
uint16_t *bnrBuf = (uint16_t *) malloc(0x80);
if (bnrBuf) {
@ -360,8 +357,8 @@ Title *loadWiiTitles() {
titles[i].saveInit = false;
}
titles[i].highID = strtoul(highIDs[k], NULL, 16);
titles[i].lowID = strtoul(data->d_name, NULL, 16);
titles[i].highID = strtoul(highIDs[k], nullptr, 16);
titles[i].lowID = strtoul(data->d_name, nullptr, 16);
titles[i].listID = i;
memcpy(titles[i].productCode, &titles[i].lowID, 4);
@ -372,7 +369,7 @@ Title *loadWiiTitles() {
titles[i].isTitleOnUSB = false;
titles[i].isTitleDupe = false;
titles[i].dupeID = 0;
if (!titles[i].saveInit || (loadTitleIcon(&titles[i]) < 0)) titles[i].iconBuf = NULL;
if (!titles[i].saveInit || (loadTitleIcon(&titles[i]) < 0)) titles[i].iconBuf = nullptr;
i++;
OSScreenClearBufferEx(SCREEN_TV, 0);
@ -436,8 +433,8 @@ int main(void) {
qsort(wiiutitles, titleswiiu, sizeof(Title), titleSort);
qsort(wiititles, titlesvwii, sizeof(Title), titleSort);
uint8_t *tgaBufDRC = NULL;
uint8_t *tgaBufTV = NULL;
uint8_t *tgaBufDRC = nullptr;
uint8_t *tgaBufTV = nullptr;
uint32_t wDRC = 0, hDRC = 0, wTV = 0, hTV = 0;
KPADStatus kpad_status;
VPADStatus vpad_status;
@ -955,10 +952,10 @@ int main(void) {
backupAllSave(wiititles, titlesvwii, &dateTime);
break;
case 1:
backupAllSave(wiiutitles, titleswiiu, NULL);
backupAllSave(wiiutitles, titleswiiu, nullptr);
break;
case 2:
backupAllSave(wiititles, titlesvwii, NULL);
backupAllSave(wiititles, titlesvwii, nullptr);
break;
}
continue;

View File

@ -56,7 +56,7 @@ int FSAR(int result) {
int32_t loadFile(const char *fPath, uint8_t **buf) {
int ret = 0;
FILE *file = fopen(fPath, "rb");
if (file != NULL) {
if (file != nullptr) {
struct stat st;
stat(fPath, &st);
int size = st.st_size;
@ -76,7 +76,7 @@ int32_t loadFile(const char *fPath, uint8_t **buf) {
int32_t loadFilePart(const char *fPath, uint32_t start, uint32_t size, uint8_t **buf) {
int ret = 0;
FILE *file = fopen(fPath, "rb");
if (file != NULL) {
if (file != nullptr) {
struct stat st;
stat(fPath, &st);
if ((start + size) > st.st_size) {
@ -132,12 +132,12 @@ int checkEntry(const char *fPath) {
int folderEmpty(const char *fPath) {
DIR *dir = opendir(fPath);
if (dir == NULL)
if (dir == nullptr)
return -1;
int c = 0;
struct dirent *data;
while ((data = readdir(dir)) != NULL) {
while ((data = readdir(dir)) != nullptr) {
if (++c > 2)
break;
}
@ -174,7 +174,7 @@ int createFolder(const char *fPath) { //Adapted from mkdir_p made by JonathonRei
}
void console_print_pos_aligned(int y, uint16_t offset, uint8_t align, const char *format, ...) {
char *tmp = NULL;
char *tmp = nullptr;
int x = 0;
va_list va;
@ -201,7 +201,7 @@ void console_print_pos_aligned(int y, uint16_t offset, uint8_t align, const char
}
void console_print_pos(int x, int y, const char *format, ...) { // Source: ftpiiu
char *tmp = NULL;
char *tmp = nullptr;
va_list va;
va_start(va, format);
@ -212,7 +212,7 @@ void console_print_pos(int x, int y, const char *format, ...) { // Source: ftpii
}
void console_print_pos_multiline(int x, int y, char cdiv, const char *format, ...) { // Source: ftpiiu
char *tmp = NULL;
char *tmp = nullptr;
uint32_t len = (66 - x);
va_list va;
@ -221,7 +221,7 @@ void console_print_pos_multiline(int x, int y, char cdiv, const char *format, ..
if ((uint32_t)(ttfStringWidth(tmp, -1) / 12) > len) {
char *p = tmp;
if (strrchr(p, '\n') != NULL) p = strrchr(p, '\n') + 1;
if (strrchr(p, '\n') != nullptr) p = strrchr(p, '\n') + 1;
while ((uint32_t)(ttfStringWidth(p, -1) / 12) > len) {
char *q = p;
int l1 = strlen(q);
@ -229,7 +229,7 @@ void console_print_pos_multiline(int x, int y, char cdiv, const char *format, ..
char o = q[l1];
q[l1] = '\0';
if ((uint32_t)(ttfStringWidth(p, -1) / 12) <= len) {
if (strrchr(p, cdiv) != NULL) p = strrchr(p, cdiv) + 1;
if (strrchr(p, cdiv) != nullptr) p = strrchr(p, cdiv) + 1;
else
p = q + l1;
q[l1] = o;
@ -252,7 +252,7 @@ void console_print_pos_multiline(int x, int y, char cdiv, const char *format, ..
}
void console_print_pos_va(int x, int y, const char *format, va_list va) { // Source: ftpiiu
char *tmp = NULL;
char *tmp = nullptr;
if ((vasprintf(&tmp, format, va) >= 0) && tmp)
ttfPrintString((x + 4) * 12, (y + 1) * 24, tmp, false, true);
@ -294,7 +294,7 @@ bool promptConfirm(Style st, const char *question) {
int ret = 0;
flipBuffers();
WHBLogFreetypeDraw();
while (1) {
while (true) {
VPADRead(VPAD_CHAN_0, &vpad_status, 1, &vpad_error);
for (int i = 0; i < 4; i++) {
WPADExtensionType controllerType;
@ -326,7 +326,7 @@ void promptError(const char *message, ...) {
va_start(va, message);
OSScreenClearBufferEx(SCREEN_TV, 0x7F000000);
OSScreenClearBufferEx(SCREEN_DRC, 0x7F000000);
char *tmp = NULL;
char *tmp = nullptr;
if ((vasprintf(&tmp, message, va) >= 0) && tmp) {
int x = 31 - (ttfStringWidth(tmp, -2) / 24), y = 8;
x = (x < -4 ? -4 : x);
@ -384,9 +384,9 @@ void getAccountsSD(Title *title, uint8_t slot) {
char path[255];
sprintf(path, "sd:/wiiu/backups/%08x%08x/%u", highID, lowID, slot);
DIR *dir = opendir(path);
if (dir != NULL) {
if (dir != nullptr) {
struct dirent *data;
while ((data = readdir(dir)) != NULL) {
while ((data = readdir(dir)) != nullptr) {
if (data->d_name[0] == '.' || strncmp(data->d_name, "common", 6) == 0) continue;
sdaccn++;
}
@ -395,13 +395,13 @@ void getAccountsSD(Title *title, uint8_t slot) {
sdacc = (Account *) malloc(sdaccn * sizeof(Account));
dir = opendir(path);
if (dir != NULL) {
if (dir != nullptr) {
struct dirent *data;
int i = 0;
while ((data = readdir(dir)) != NULL) {
while ((data = readdir(dir)) != nullptr) {
if (data->d_name[0] == '.' || strncmp(data->d_name, "common", 6) == 0) continue;
sprintf(sdacc[i].persistentID, "%s", data->d_name);
sdacc[i].pID = strtoul(data->d_name, NULL, 16);
sdacc[i].pID = strtoul(data->d_name, nullptr, 16);
sdacc[i].slot = i;
i++;
}
@ -411,11 +411,11 @@ void getAccountsSD(Title *title, uint8_t slot) {
int DumpFile(string pPath, string oPath) {
FILE *source = fopen(pPath.c_str(), "rb");
if (source == NULL)
if (source == nullptr)
return -1;
FILE *dest = fopen(oPath.c_str(), "wb");
if (dest == NULL) {
if (dest == nullptr) {
fclose(source);
return -1;
}
@ -423,7 +423,7 @@ int DumpFile(string pPath, string oPath) {
char *buffer[3];
for (int i = 0; i < 3; i++) {
buffer[i] = (char *) aligned_alloc(0x40, IO_MAX_FILE_BUFFER);
if (buffer[i] == NULL) {
if (buffer[i] == nullptr) {
fclose(source);
fclose(dest);
for (i--; i >= 0; i--)
@ -475,13 +475,13 @@ int DumpFile(string pPath, string oPath) {
int DumpDir(string pPath, string tPath) { // Source: ft2sd
DIR *dir = opendir(pPath.c_str());
if (dir == NULL)
if (dir == nullptr)
return -1;
mkdir(tPath.c_str(), DEFFILEMODE);
struct dirent *data = (dirent *) malloc(sizeof(dirent));
while ((data = readdir(dir)) != NULL) {
while ((data = readdir(dir)) != nullptr) {
OSScreenClearBufferEx(SCREEN_TV, 0);
OSScreenClearBufferEx(SCREEN_DRC, 0);
@ -513,12 +513,12 @@ int DumpDir(string pPath, string tPath) { // Source: ft2sd
int DeleteDir(char *pPath) {
DIR *dir = opendir(pPath);
if (dir == NULL)
if (dir == nullptr)
return -1;
struct dirent *data;
while ((data = readdir(dir)) != NULL) {
while ((data = readdir(dir)) != nullptr) {
OSScreenClearBufferEx(SCREEN_TV, 0);
OSScreenClearBufferEx(SCREEN_DRC, 0);
@ -567,11 +567,11 @@ void getUserID(char *out) { // Source: loadiine_gx2
int getLoadiineGameSaveDir(char *out, const char *productCode) {
DIR *dir = opendir("sd:/wiiu/saves");
if (dir == NULL) return -1;
if (dir == nullptr) return -1;
struct dirent *data;
while ((data = readdir(dir)) != NULL) {
if ((data->d_type & DT_DIR) && (strstr(data->d_name, productCode) != NULL)) {
while ((data = readdir(dir)) != nullptr) {
if ((data->d_type & DT_DIR) && (strstr(data->d_name, productCode) != nullptr)) {
sprintf(out, "sd:/wiiu/saves/%s", data->d_name);
closedir(dir);
return 0;
@ -586,16 +586,16 @@ int getLoadiineGameSaveDir(char *out, const char *productCode) {
int getLoadiineSaveVersionList(int *out, const char *gamePath) {
DIR *dir = opendir(gamePath);
if (dir == NULL) {
if (dir == nullptr) {
promptError("Loadiine game folder not found.");
return -1;
}
int i = 0;
struct dirent *data;
while (i < 255 && (data = readdir(dir)) != NULL) {
if ((data->d_type & DT_DIR) && (strchr(data->d_name, 'v') != NULL)) {
out[++i] = strtol((data->d_name) + 1, NULL, 10);
while (i < 255 && (data = readdir(dir)) != nullptr) {
if ((data->d_type & DT_DIR) && (strchr(data->d_name, 'v') != nullptr)) {
out[++i] = strtol((data->d_name) + 1, nullptr, 10);
}
}
@ -606,13 +606,13 @@ int getLoadiineSaveVersionList(int *out, const char *gamePath) {
int getLoadiineUserDir(char *out, const char *fullSavePath, const char *userID) {
DIR *dir = opendir(fullSavePath);
if (dir == NULL) {
if (dir == nullptr) {
promptError("Failed to open Loadiine game save directory.");
return -1;
}
struct dirent *data;
while ((data = readdir(dir)) != NULL) {
while ((data = readdir(dir)) != nullptr) {
if ((data->d_type & DT_DIR) && (strstr(data->d_name, userID))) {
sprintf(out, "%s/%s", fullSavePath, data->d_name);
closedir(dir);
@ -634,9 +634,9 @@ bool isSlotEmpty(uint32_t highID, uint32_t lowID, uint8_t slot) {
sprintf(path, "sd:/wiiu/backups/%08x%08x/%u", highID, lowID, slot);
}
int ret = checkEntry(path);
if (ret <= 0) return 1;
if (ret <= 0) return true;
else
return 0;
return false;
}
int getEmptySlot(uint32_t highID, uint32_t lowID) {

View File

@ -16,6 +16,6 @@ char *replace_str(char *str, char *orig, char *rep) {
}
bool StartsWith(const char *a, const char *b) {
if (strncmp(a, b, strlen(b)) == 0) return 1;
return 0;
if (strncmp(a, b, strlen(b)) == 0) return true;
return false;
}

View File

@ -2,10 +2,8 @@
#include <string>
#include <stdarg.h>
#include <stdexcept>
extern "C" {
#include "savemng.h"
}
using namespace std;
char *replace_str(char *str, char *orig, char *rep);

View File

@ -79,7 +79,7 @@ int *tgaRead(const unsigned char *buffer, const TGA_ORDER *order) {
int depth = buffer[16] & 0xFF;
int descriptor = buffer[17] & 0xFF;
int *pixels = NULL;
int *pixels = nullptr;
// data
switch (type) {
@ -155,7 +155,7 @@ static unsigned char *decodeRLE(int width, int height, int depth, const unsigned
static int *createPixelsFromColormap(int width, int height, int depth, const unsigned char *bytes, int offset,
const unsigned char *palette, int colormapOrigin, int descriptor,
const TGA_ORDER *order) {
int *pixels = NULL;
int *pixels = nullptr;
int rs = order->redShift;
int gs = order->greenShift;
int bs = order->blueShift;
@ -330,7 +330,7 @@ static int *createPixelsFromColormap(int width, int height, int depth, const uns
static int *
createPixelsFromRGB(int width, int height, int depth, const unsigned char *bytes, int offset, int descriptor,
const TGA_ORDER *order) {
int *pixels = NULL;
int *pixels = nullptr;
int rs = order->redShift;
int gs = order->greenShift;
int bs = order->blueShift;
@ -467,7 +467,7 @@ createPixelsFromRGB(int width, int height, int depth, const unsigned char *bytes
static int *
createPixelsFromGrayscale(int width, int height, int depth, const unsigned char *bytes, int offset, int descriptor,
const TGA_ORDER *order) {
int *pixels = NULL;
int *pixels = nullptr;
int rs = order->redShift;
int gs = order->greenShift;
int bs = order->blueShift;

View File

@ -1,5 +0,0 @@
#ifndef WIIU_H
#define WIIU_H
#endif // WIIU_H