Skip to content

Commit d1fe7ef

Browse files
author
Gonzalo Diaz
committed
[REFACTOR] [Hacker Rank] Warmup: Time Conversion solved ✅. Trying to solve sonarcloud warnings.
1 parent 2e82490 commit d1fe7ef

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

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

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,16 @@
88
#include <stdlib.h>
99
#include <string.h>
1010

11+
#define HACKERRANK_WARMUP_MAX_STRING_SIZE 10
12+
1113
char *HACKERRANK_WARMUP_getFirst(const char *s, unsigned long n) {
12-
return HACKERRANK_WARMUP_getStringFragment(s, strlen(s), 0, n);
14+
char dest[HACKERRANK_WARMUP_MAX_STRING_SIZE + 1];
15+
strncpy(dest, s, sizeof dest);
16+
dest[sizeof dest - 1] = 0;
17+
size_t s_len = strlen(s);
18+
strlen(dest);
19+
20+
return HACKERRANK_WARMUP_getStringFragment(s, s_len, 0, n);
1321
}
1422

1523
char *HACKERRANK_WARMUP_getLast(const char *s, unsigned long n) {

0 commit comments

Comments
 (0)