Skip to content

Commit

Permalink
ARC: [lib] strchr breakage in Big-endian configuration
Browse files Browse the repository at this point in the history
For a search buffer, 2 byte aligned, strchr() was returning pointer
outside of buffer (buf - 1)

------------->8----------------
    // Input buffer (default 4 byte aigned)
    char *buffer = "1AA_";

    // actual search start (to mimick 2 byte alignment)
    char *current_line = &(buffer[2]);

    // Character to search for
    char c = 'A';

    char *c_pos = strchr(current_line, c);

    printf("%s\n", c_pos) --> 'AA_' as oppose to 'A_'
------------->8----------------

Reported-by: Anton Kolesov <[email protected]>
Debugged-by: Anton Kolesov <[email protected]>
Cc: <[email protected]> # [3.9 and 3.10]
Cc: Noam Camus <[email protected]>
Signed-off-by: Joern Rennecke  <[email protected]>
Signed-off-by: Vineet Gupta <[email protected]>
Signed-off-by: Linus Torvalds <[email protected]>
  • Loading branch information
amylaar authored and torvalds committed Aug 24, 2013
1 parent 89b53e5 commit b0f55f2
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions arch/arc/lib/strchr-700.S
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,18 @@ ARC_ENTRY strchr
ld.a r2,[r0,4]
sub r12,r6,r7
bic r12,r12,r6
#ifdef __LITTLE_ENDIAN__
and r7,r12,r4
breq r7,0,.Loop ; For speed, we want this branch to be unaligned.
b .Lfound_char ; Likewise this one.
#else
and r12,r12,r4
breq r12,0,.Loop ; For speed, we want this branch to be unaligned.
lsr_s r12,r12,7
bic r2,r7,r6
b.d .Lfound_char_b
and_s r2,r2,r12
#endif
; /* We require this code address to be unaligned for speed... */
.Laligned:
ld_s r2,[r0]
Expand Down Expand Up @@ -95,6 +104,7 @@ ARC_ENTRY strchr
lsr r7,r7,7

bic r2,r7,r6
.Lfound_char_b:
norm r2,r2
sub_s r0,r0,4
asr_s r2,r2,3
Expand Down

0 comments on commit b0f55f2

Please sign in to comment.