Skip to content

Commit ff3d4d2

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

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

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

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,12 @@
1212

1313
char *HACKERRANK_WARMUP_getFirst(const char *s, unsigned long n) {
1414
char dest[HACKERRANK_WARMUP_MAX_STRING_SIZE + 1];
15-
strncpy(dest, s, sizeof dest);
1615
dest[sizeof dest - 1] = 0;
16+
strncpy(dest, s, sizeof dest);
17+
if (dest[sizeof dest - 1] != 0) {
18+
return NULL; // Handle error
19+
}
1720
size_t s_len = strlen(s);
18-
strlen(dest);
1921

2022
return HACKERRANK_WARMUP_getStringFragment(s, s_len, 0, n);
2123
}

0 commit comments

Comments
 (0)