Skip to content

Commit

Permalink
Typecast pointers for C++ compatibility
Browse files Browse the repository at this point in the history
  • Loading branch information
dr8co committed Apr 6, 2024
1 parent 162a0a8 commit 8a32290
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions lite_str.h
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@ bool string_shrink_to_fit(lite_string *restrict s);
* @note The returned pointer must be freed by the caller, using \p string_free
*/
lite_string *string_new() {
lite_string *s = malloc(sizeof(lite_string));
lite_string *s = (lite_string *) malloc(sizeof(lite_string));
if (s) {
if ((s->data = (char *) calloc(16, sizeof(char)))) {
s->size = 0;
Expand Down Expand Up @@ -706,7 +706,7 @@ bool string_append_cstr(lite_string *const restrict s, const char *const restric
char *string_cstr(const lite_string *const restrict s) {
if (s) {
// Allocate memory for the C-string
char *cstr = malloc((s->size + 1) * sizeof(char));
char *cstr = (char *) malloc((s->size + 1) * sizeof(char));
if (cstr) {
// Copy the characters from the string to the C-string
memcpy(cstr, s->data, s->size);
Expand Down Expand Up @@ -1134,7 +1134,7 @@ bool string_shrink_to_fit(lite_string *const restrict s) {
// If the string is empty, or if the size is equal to the capacity, no resizing is necessary
if (!s->size || s->size == s->capacity) return true;

char *temp = realloc(s->data, s->size * sizeof(char));
char *temp = (char *) realloc(s->data, s->size * sizeof(char));
if (temp) {
s->data = temp;
s->capacity = s->size;
Expand Down

0 comments on commit 8a32290

Please sign in to comment.