Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 8f5ec3d

Browse files
fix strstr
1 parent 38f4106 commit 8f5ec3d

File tree

2 files changed

+10
-2
lines changed

2 files changed

+10
-2
lines changed

‎0x09-libasm/4-strstr.asm‎

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,13 @@ asm_strstr:
1818
movr15b,0 ; variable char *str
1919
movr14b,0 ; variable char *substr
2020
movr13b,0
21+
22+
cmp[rsi], byte 0 ; if (!*str)
23+
movr15,rdi
24+
je end
2125
;loop_str - while loop
2226
loop_str:
23-
cmp[rdi], byte 0 ; while (*str)
27+
cmp[rdi], byte 0 ; while (!*str)
2428
je nullend
2529
movr15,rdi ; *Begin = *str;
2630
movr14,rsi ; *pattern = *substr;

‎0x09-libasm/main/4-main.c‎

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
#define S1 "Holberton School"
99
#define S2 "School"
1010
#define S3 "Socool"
11+
#define S4 ""
1112

1213
/**
1314
char* asm_strstr(const char *str, sonst char *substr)
@@ -19,7 +20,7 @@ char* asm_strstr(const char *str, sonst char *substr)
1920
2021
// If first character of sub string match, check for whole string
2122
while (*str && *pattern && *str == *pattern)
22-
{
23+
{
2324
str++;
2425
pattern++;
2526
}
@@ -41,7 +42,10 @@ int main(void)
4142
{
4243
assert(strstr(S1, S2) == asm_strstr(S1, S2));
4344
assert(strstr(S1, S3) == asm_strstr(S1, S3));
45+
assert(strstr(S1, S4) == asm_strstr(S1, S4));
4446
assert(strstr(S1, S1) == asm_strstr(S1, S1));
47+
assert(strstr(S4, S4) == asm_strstr(S4, S4));
48+
assert(strstr(S4, S1) == asm_strstr(S4, S1));
4549

4650
printf("All good!\n");
4751
return (EXIT_SUCCESS);

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /