Bug 10220 - Fix inverted memmove parameters in glibc manual example 'file_mbsrtowcs'
Summary: Fix inverted memmove parameters in glibc manual example 'file_mbsrtowcs'
Status: VERIFIED FIXED
Alias: None
Product: glibc
Classification: Unclassified
Component: manual (show other bugs)
Version: 2.11
: P2 normal
Target Milestone: ---
Assignee: Roland McGrath
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2009-05-30 09:09 UTC by André Goddard Rosa
Modified: 2014-07-01 20:15 UTC (History)
1 user (show)

See Also:
Host:
Target:
Build:
Last reconfirmed:
fweimer: security-


Attachments
proposed patch (815 bytes, patch)
2009-05-30 09:14 UTC, André Goddard Rosa
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description André Goddard Rosa 2009-05-30 09:09:54 UTC
On section 6.3.5 - "A Complete Multibyte Conversion Example" the example 
describe an algorithm to convert an NUL-terminated multibyte character string at 
into an equivalent wide character string. It does:

1. read from input file to temp buffer
2. convert characters in temp buffer
3. write to output file the converted characters
4. go to step one, but first copy incomplete sequence to start of temp buffer

The pass four is implemented by a memmove(), taking an incomplete at the end of 
the buffer and repositioning it at the start of the buffer.

ERROR:
------
 The aforementioned memmove() has its parameters inverted, because it`s
 not putting the remaining characters in the beginning of the buffer.

Instead of:
    memmove (inp, buffer, filled);

It should obviously be:
    memmove (buffer, inp, filled);
Comment 1 André Goddard Rosa 2009-05-30 09:14:08 UTC
Created attachment 3976 [details]
proposed patch

proposed fix
Comment 2 André Goddard Rosa 2009-06-02 14:36:11 UTC
Commited on: http://repo.or.cz/w/glibc.git?
a=commit;h=21e66bc528edcbe18d434eb33a601e0f796904c9
Comment 3 André Goddard Rosa 2009-06-02 14:38:46 UTC
Fix is available from latest sources now.