VirtualBox

Changeset 26839 in vbox for trunk/src/VBox/Runtime/r3/linux


Ignore:
Timestamp:
Feb 26, 2010 12:38:55 PM (15 years ago)
Author:
vboxsync
Message:

RTSystemQueryDmiString-linux.cpp: fixed edge case.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Runtime/r3/linux/RTSystemQueryDmiString-linux.cpp

    r26618 r26839  
    6767    if (fd >= 0)
    6868    {
    69         /* Note! This will return VERR_BUFFER_OVERFLOW even if there is a
    70                  trailing newline that we don't care about. */
    7169        size_t cbRead;
    72         rc = RTLinuxSysFsReadFile(fd, pszBuf, cbBuf - 1, &cbRead);
     70        rc = RTLinuxSysFsReadFile(fd, pszBuf, cbBuf, &cbRead);
    7371        if (RT_SUCCESS(rc) || rc == VERR_BUFFER_OVERFLOW)
    7472        {
    75             pszBuf[cbRead] = '\0';
    76             while (cbRead > 0 && pszBuf[cbRead - 1] == '\n')
    77                 pszBuf[--cbRead] = '\0';
     73            /* The file we're reading may end with a newline, remove it. */
     74            if (cbRead == cbBuf)
     75                pszBuf[cbRead - 1] = '\0';
     76            else
     77            {
     78                AssertRC(rc);
     79                pszBuf[cbRead] = '\0';
     80                if (cbRead > 0 && pszBuf[cbRead - 1] == '\n')
     81                    pszBuf[cbRead - 1] = '\0';
     82            }
    7883        }
    7984        RTLinuxSysFsClose(fd);
Note: See TracChangeset for help on using the changeset viewer.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette