VirtualBox

Changeset 83745 in vbox for trunk/src/VBox/Runtime/win


Ignore:
Timestamp:
Apr 17, 2020 12:33:33 PM (5 years ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
137266
Message:

IPRT: Sort IPRT status messages so we can look them up using binary searching. bugref:8489

Location:
trunk/src/VBox/Runtime/win
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Runtime/win/errmsgwin-sorter.cpp

    r83744 r83745  
    8585
    8686
     87/**
     88 * Escapes @a pszString using @a pszBuf as needed.
     89 * @note Duplicated in errmsg-sorter.cpp.
     90 */
     91static const char *EscapeString(const char *pszString, char *pszBuf, size_t cbBuf)
     92{
     93    if (strpbrk(pszString, "\n\t\r\"\\") == NULL)
     94        return pszString;
     95
     96    char *pszDst = pszBuf;
     97    char  ch;
     98    do
     99    {
     100        ch = *pszString++;
     101        switch (ch)
     102        {
     103            default:
     104                *pszDst++ = ch;
     105                break;
     106            case '\\':
     107            case '"':
     108                *pszDst++ = '\\';
     109                *pszDst++ = ch;
     110                break;
     111            case '\n':
     112                *pszDst++ = '\\';
     113                *pszDst++ = 'n';
     114                break;
     115            case '\t':
     116                *pszDst++ = '\\';
     117                *pszDst++ = 't';
     118                break;
     119            case '\r':
     120                break; /* drop it */
     121        }
     122    } while (ch);
     123
     124    if ((uintptr_t)(pszDst - pszBuf) > cbBuf)
     125        fprintf(stderr, "Escape buffer overrun!\n");
     126
     127    return pszBuf;
     128}
     129
     130
    87131int main(int argc, char **argv)
    88132{
     
    138182            iPrev = pMsg->iCode;
    139183
    140             /* Make sure the message string doesn't contain problematic characters: */
    141             const char *pszMsgFull = pMsg->pszMsgFull;
    142             if (strpbrk(pszMsgFull, "\"\\"))
    143             {
    144                 char *pszDst = s_szMsgTmp;
    145                 char  ch;
    146                 do
    147                 {
    148                     ch = *pszMsgFull++;
    149                     if (ch == '\\' || ch == '"')
    150                         *pszDst++ = '\\';
    151                     *pszDst++ = ch;
    152                 } while (ch);
    153                 pszMsgFull = s_szMsgTmp;
    154             }
    155 
    156184            /* Produce the output: */
    157             fprintf(pOut, "/*%#010lx:*/ { \"%s\", \"%s\", %ld },\n",
    158                     (unsigned long)pMsg->iCode, pszMsgFull, pMsg->pszDefine, pMsg->iCode);
     185            fprintf(pOut, "/*%#010lx:*/ { \"%s\", \"%s\", %ld },\n", (unsigned long)pMsg->iCode,
     186                    EscapeString(pMsg->pszMsgFull, s_szMsgTmp, sizeof(s_szMsgTmp)), pMsg->pszDefine, pMsg->iCode);
    159187        }
    160188
  • trunk/src/VBox/Runtime/win/errmsgwin.cpp

    r83744 r83745  
    8181{
    8282    /*
    83      * Perform binary search.
     83     * Perform binary search (duplicate code in RTErrGet).
    8484     */
    8585    size_t iStart = 0;
Note: See TracChangeset for help on using the changeset viewer.

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