Ticket #8983: 0002-Fix-gcc-warnings-when-compiling-with-DFORTIFY_SOURC.patch

File 0002-Fix-gcc-warnings-when-compiling-with-DFORTIFY_SOURC.patch, 5.8 KB (added by SF/raorn, 16 years ago)

gcc-wanings.patch

  • scummvm/backends/fs/posix/posix-fs-factory.cpp

    From 0aa2e39e1d4ad87552bfc3811fb228374586abe3 Mon Sep 17 00:00:00 2001
    From: Alexey I. Froloff <raorn@altlinux.org>
    Date: Thu, 12 Mar 2009 14:34:16 +0300
    Subject: [PATCH 2/2] Fix gcc warnings when compiling with -DFORTIFY_SOURCE=2 -fstack-protector
    
    Some warnings may cause "glibc detected buffer overflow" runtime errors.
    
    In function 'char* strncat(char*, const char*, size_t)',
        inlined from 'virtual int32 Scumm::LogicHE::dispatch(int, int, int32*)' at engines/scumm/he/logic_he.cpp:89:
    /usr/include/bits/string3.h:153: warning: call to char* __builtin___strncat_chk(char*, const char*, unsigned int, unsigned int) might overflow destination buffer
    In function 'char* strncat(char*, const char*, size_t)',
        inlined from 'void Saga::Script::sfStub(const char*, Saga::ScriptThread*, int)' at engines/saga/sfuncs.cpp:1573:
    /usr/include/bits/string3.h:153: warning: call to char* __builtin___strncat_chk(char*, const char*, unsigned int, unsigned int) might overflow destination buffer
    
    strncat(3) wants size_t n as "available space in destination buffer",
    not total buffer size.  Pass correct size to strncat(3).
    
    backends/fs/posix/posix-fs-factory.cpp: In member function 'virtual AbstractFSNode* POSIXFilesystemFactory::makeCurrentDirectoryFileNode() const':
    backends/fs/posix/posix-fs-factory.cpp:35: warning: ignoring return value of 'char* getcwd(char*, size_t)', declared with attribute warn_unused_result
    
    Return NULL if getcwd(3) fails.
    
    backends/midi/seq.cpp: In member function 'virtual void MidiDriver_SEQ::send(uint32)':
    backends/midi/seq.cpp:145: warning: ignoring return value of 'ssize_t write(int, const void*, size_t)', declared with attribute warn_unused_result
    backends/midi/seq.cpp: In member function 'virtual void MidiDriver_SEQ::sysEx(const byte*, uint16)':
    backends/midi/seq.cpp:170: warning: ignoring return value of 'ssize_t write(int, const void*, size_t)', declared with attribute warn_unused_result
    backends/midi/timidity.cpp: In member function 'char* MidiDriver_TIMIDITY::timidity_ctl_command(const char*, ...)':
    backends/midi/timidity.cpp:336: warning: ignoring return value of 'ssize_t write(int, const void*, size_t)', declared with attribute warn_unused_result
    
    Emit warning if write(2) fails.
    
    Signed-off-by: Alexey I. Froloff <raorn@altlinux.org>
    ---
     scummvm/backends/fs/posix/posix-fs-factory.cpp |    3 +--
     scummvm/backends/midi/seq.cpp                  |    7 +++++--
     scummvm/backends/midi/timidity.cpp             |    4 +++-
     scummvm/engines/saga/sfuncs.cpp                |    4 ++--
     scummvm/engines/scumm/he/logic_he.cpp          |    4 ++--
     5 files changed, 13 insertions(+), 9 deletions(-)
    
    diff --git a/scummvm/backends/fs/posix/posix-fs-factory.cpp b/scummvm/backends/fs/posix/posix-fs-factory.cpp
    index ad6e871..3dffb99 100644
    a b AbstractFSNode *POSIXFilesystemFactory::makeRootFileNode() const {  
    3232
    3333AbstractFSNode *POSIXFilesystemFactory::makeCurrentDirectoryFileNode() const {
    3434        char buf[MAXPATHLEN];
    35         getcwd(buf, MAXPATHLEN);
    36         return new POSIXFilesystemNode(buf);
     35        return getcwd(buf, MAXPATHLEN) ? new POSIXFilesystemNode(buf) : NULL;
    3736}
    3837
    3938AbstractFSNode *POSIXFilesystemFactory::makeFileNodePath(const Common::String &path) const {
  • scummvm/backends/midi/seq.cpp

    diff --git a/scummvm/backends/midi/seq.cpp b/scummvm/backends/midi/seq.cpp
    index 0c3ee33..0795dca 100644
    a b  
    3636
    3737#include <fcntl.h>
    3838#include <unistd.h>
     39#include <errno.h>
    3940
    4041////////////////////////////////////////
    4142//
    void MidiDriver_SEQ::send(uint32 b) {  
    142143                warning("MidiDriver_SEQ::send: unknown : %08x", (int)b);
    143144                break;
    144145        }
    145         write(device, buf, position);
     146        if (write(device, buf, position) < 0)
     147                warning("MidiDriver_SEQ::send: write(): %s", strerror(errno));
    146148}
    147149
    148150void MidiDriver_SEQ::sysEx (const byte *msg, uint16 length) {
    void MidiDriver_SEQ::sysEx (const byte *msg, uint16 length) {  
    167169        buf[position++] = _device_num;
    168170        buf[position++] = 0;
    169171
    170         write (device, buf, position);
     172        if (write (device, buf, position) < 0)
     173                warning("MidiDriver_SEQ::sysEx: write(): %s", strerror(errno));
    171174}
    172175
    173176
  • scummvm/backends/midi/timidity.cpp

    diff --git a/scummvm/backends/midi/timidity.cpp b/scummvm/backends/midi/timidity.cpp
    index 9f119b6..8eeb7c8 100644
    a b char *MidiDriver_TIMIDITY::timidity_ctl_command(const char *fmt, ...) {  
    333333                        buff[len++] = '\n';
    334334
    335335                /* write command to control socket */
    336                 write(_control_fd, buff, len);
     336                if (write(_control_fd, buff, len) < 0) {
     337                        warning("TiMidity: write(): %s", strerror(errno));
     338                }
    337339        }
    338340
    339341        while (1) {
  • scummvm/engines/saga/sfuncs.cpp

    diff --git a/scummvm/engines/saga/sfuncs.cpp b/scummvm/engines/saga/sfuncs.cpp
    index cc80fbc..91f24ea 100644
    a b void Script::sfStub(const char *name, ScriptThread *thread, int nArgs) {  
    15701570
    15711571        for (int i = 0; i < nArgs; i++) {
    15721572                snprintf(buf1, 100, "%d", thread->pop());
    1573                 strncat(buf, buf1, 256);
     1573                strncat(buf, buf1, sizeof(buf) - strlen(buf) - 1);
    15741574                if (i + 1 < nArgs)
    1575                         strncat(buf, ", ", 256);
     1575                        strncat(buf, ", ", sizeof(buf) - strlen(buf) - 1);
    15761576        }
    15771577
    15781578        debug(0, "%s)", buf);
  • scummvm/engines/scumm/he/logic_he.cpp

    diff --git a/scummvm/engines/scumm/he/logic_he.cpp b/scummvm/engines/scumm/he/logic_he.cpp
    index 255deea..f95b31c 100644
    a b int32 LogicHE::dispatch(int op, int numArgs, int32 *args) {  
    8686
    8787        for (int i = 1; i < numArgs; i++) {
    8888                snprintf(tmp, 32, ", %d", args[i]);
    89                 strncat(str, tmp, 256);
     89                strncat(str, tmp, sizeof(str) - strlen(str) - 1);
    9090        }
    91         strncat(str, "])", 256);
     91        strncat(str, "])", sizeof(str) - strlen(str) - 1);
    9292
    9393        debug(0, "%s", str);
    9494#else