Skip to content

Commit 3bc6054

Browse files
committed
Handle negative n case at the start
1 parent 6e413f6 commit 3bc6054

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

src/libasr/runtime/lfortran_intrinsics.c

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2135,12 +2135,18 @@ LFORTRAN_API int32_t _lpython_bit_length8(int64_t num)
21352135
//repeat str for n time
21362136
LFORTRAN_API void _lfortran_strrepeat(char** s, int32_t n, char** dest)
21372137
{
2138+
// Return empty string for non-positive n
2139+
if (n <= 0) {
2140+
char* dest_char = (char*)malloc(1);
2141+
dest_char[0] = '\0';
2142+
*dest = dest_char;
2143+
return;
2144+
}
2145+
21382146
char trmn = '\0';
21392147
int s_len = strlen(*s);
21402148
int trmn_size = sizeof(trmn);
21412149
int f_len = s_len*n;
2142-
if (f_len < 0)
2143-
f_len = 0;
21442150
char* dest_char = (char*)malloc(f_len+trmn_size);
21452151

21462152
if (s_len == 1) {

0 commit comments

Comments
 (0)