[commit: ghc] master: Use snwprintf instead of swprintf in rts/Linker.c. (5ce1266)

git at git.haskell.org git at git.haskell.org
Thu Oct 30 04:15:40 UTC 2014


Repository : ssh://git@git.haskell.org/ghc

On branch  : master
Link       : http://ghc.haskell.org/trac/ghc/changeset/5ce1266a7d323fd4fe4262f07be908d65e5b5b43/ghc

>---------------------------------------------------------------

commit 5ce1266a7d323fd4fe4262f07be908d65e5b5b43
Author: Gintautas Miliauskas <gintautas.miliauskas at gmail.com>
Date:   Wed Oct 29 23:13:31 2014 -0500

    Use snwprintf instead of swprintf in rts/Linker.c.
    
    Summary:
    swprintf has different signatures in mingw32, where it does not include the
    buffer size, and in mingw-w64, where it does. That of course breaks the code
    as mingw-w64 treats the pointer to the format string as a size_t.
    
    snwprintf is available in both environments and is consistent, so use that
    instead.
    
    Reviewers: simonmar, austin
    
    Reviewed By: austin
    
    Subscribers: #ghc_windows_task_force, thomie, carter, simonmar
    
    Differential Revision: https://phabricator.haskell.org/D372
    
    GHC Trac Issues: #9726


>---------------------------------------------------------------

5ce1266a7d323fd4fe4262f07be908d65e5b5b43
 rts/Linker.c | 9 +++++----
 1 file changed, 5 insertions(+), 4 deletions(-)

diff --git a/rts/Linker.c b/rts/Linker.c
index 35cee2c..7d029c6 100644
--- a/rts/Linker.c
+++ b/rts/Linker.c
@@ -1968,18 +1968,19 @@ addDLL( pathchar *dll_name )
         point character (.) to indicate that the module name has no
         extension. */
 
-   buf = stgMallocBytes((pathlen(dll_name) + 10) * sizeof(wchar_t), "addDLL");
-   swprintf(buf, L"%s.DLL", dll_name);
+   size_t bufsize = pathlen(dll_name) + 10;
+   buf = stgMallocBytes(bufsize * sizeof(wchar_t), "addDLL");
+   snwprintf(buf, bufsize, L"%s.DLL", dll_name);
    instance = LoadLibraryW(buf);
    if (instance == NULL) {
        if (GetLastError() != ERROR_MOD_NOT_FOUND) goto error;
        // KAA: allow loading of drivers (like winspool.drv)
-       swprintf(buf, L"%s.DRV", dll_name);
+       snwprintf(buf, bufsize, L"%s.DRV", dll_name);
        instance = LoadLibraryW(buf);
        if (instance == NULL) {
            if (GetLastError() != ERROR_MOD_NOT_FOUND) goto error;
            // #1883: allow loading of unix-style libfoo.dll DLLs
-           swprintf(buf, L"lib%s.DLL", dll_name);
+           snwprintf(buf, bufsize, L"lib%s.DLL", dll_name);
            instance = LoadLibraryW(buf);
            if (instance == NULL) {
                goto error;



More information about the ghc-commits mailing list