1
1
mirror of https://github.com/theoludwig/programming-challenges.git synced 2025-05-18 12:02:53 +02:00

fix(solutions): memory issues thanks to -fsanitize=address flag with gcc

This commit is contained in:
2023-08-10 11:13:06 +02:00
parent 3b6cc97bb5
commit 0245c7a12c
96 changed files with 712 additions and 453 deletions

View File

@ -1,9 +1,5 @@
#include "character.h"
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
void character_append(char* string, char character) {
size_t length = strlen(string);
string[length] = character;

View File

@ -1,7 +1,9 @@
#ifndef __CHARACTER__
#define __CHARACTER__
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
/**
* @brief Append a character to a string, assuming string points to an array

View File

@ -1,10 +1,5 @@
#include "input.h"
#include <stdio.h>
#include <stdlib.h>
#include "character.h"
char* input() {
char character;
size_t length = 1;

View File

@ -1,6 +1,11 @@
#ifndef __INPUT__
#define __INPUT__
#include <stdio.h>
#include <stdlib.h>
#include "character.h"
/**
* @brief Read a line from stdin.
*

View File

@ -7,10 +7,10 @@
int main() {
char* type = input();
int height;
scanf("%d", &height);
unsigned long height;
scanf("%lu", &height);
int step = strcmp(type, "normal") == 0 ? 1 : height;
unsigned long step = strcmp(type, "normal") == 0 ? 1 : height;
while ((strcmp(type, "normal") == 0 && step <= height) || (strcmp(type, "reverse") == 0 && step != 0)) {
size_t numberOfStars = (step * 2) - 1;
size_t totalNumberOfLocations = (height * 2) - 1;
@ -23,5 +23,6 @@ int main() {
step = strcmp(type, "normal") == 0 ? step + 1 : step - 1;
}
free(type);
return EXIT_SUCCESS;
}