Skip to content

Commit 9f5d5a0

Browse files
author
Gonzalo Diaz
committed
[REFACTOR] [Hacker Rank] Warmup: Time Conversion solved ✅. Triying to fix sonarlint detected issues.
1 parent a3156cb commit 9f5d5a0

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

src/lib/exercises/src/hackerrank/warmup/time_conversion.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,6 @@
88
#include <stdlib.h>
99
#include <string.h>
1010

11-
#define TIME_SIZE 11 // hh:mm:ssXX 10 + 1 for null terminator
12-
1311
char *HACKERRANK_WARMUP_getFirst(const char *s, unsigned long n) {
1412
return HACKERRANK_WARMUP_getStringFragment(s, strlen(s), 0, n);
1513
}
@@ -49,7 +47,8 @@ char *HACKERRANK_WARMUP_timeConversion(const char *s) {
4947
char *meridian = HACKERRANK_WARMUP_getLast(s, 2);
5048
char *hour_str = HACKERRANK_WARMUP_getFirst(s, 2);
5149

52-
char time_str[TIME_SIZE];
50+
char *time_str = malloc(strlen(s) + 1);
51+
5352
strcpy(time_str, s);
5453
char *temp_time_str;
5554
unsigned long time_str_len = strlen(time_str);
@@ -66,8 +65,9 @@ char *HACKERRANK_WARMUP_timeConversion(const char *s) {
6665
if (*endptr != '\0') {
6766
printf("Conversion error, non-convertible part: %s\n", endptr);
6867

69-
free(hour_str);
7068
free(meridian);
69+
free(hour_str);
70+
free(time_str);
7171
free(endptr);
7272
return NULL;
7373
} else {

0 commit comments

Comments
 (0)