VirtualBox

儲存庫 vbox 的更動 63272


忽略:
時間撮記:
2016-8-10 下午02:03:34 (8 年 以前)
作者:
vboxsync
訊息:

netPfStrPortParse: Rewrite to deal with warnings.

檔案:
修改 1 筆資料

圖例:

未更動
新增
刪除
  • trunk/src/VBox/NetworkServices/NetLib/VBoxNetPortForwardString.cpp

    r63267 r63272  
    9393
    9494
     95/**
     96 * Parses a port something.
     97 *
     98 * @returns Offset relative to @a pszRaw of the end of the port field.
     99 *          -1 on failure.
     100 * @param   pszRaw          The zero terminated string to parse.  Points a field
     101 *                          separator.
     102 * @param   cbRaw           Number of valid bytes in the buffer @a pszRaw points
     103 *                          at.  (Ignored since pszRaw is terminated.)
     104 * @param   pu16Port        Where to store the port number on success.
     105 */
    95106static int netPfStrPortParse(char *pszRaw, int cbRaw, uint16_t *pu16Port)
    96107{
     108#if 1
     109    AssertPtrReturn(pszRaw, -1);
     110    AssertPtrReturn(pu16Port, -1);
     111    AssertReturn(pszRaw[0] == PF_FIELD_SEPARATOR, -1);
     112
     113    char *pszNext = NULL;
     114    int rc = RTStrToUInt16Ex(&pszRaw[1], &pszNext, 0, pu16Port);
     115    if (rc == VWRN_TRAILING_CHARS)
     116        AssertReturn(*pszNext == PF_FIELD_SEPARATOR, -1);
     117    else if (rc == VINF_SUCCESS)
     118        Assert(*pszNext == '\0');
     119    else
     120        AssertMsgFailedReturn(("rc=%Rrc\n", rc), -1);
     121    if (*pu16Port == 0)
     122        return -1;
     123    Assert((uinpttr_t)pszNext <= (uintptr_t)&pszRaw[cbRaw]); NOREF(cbRaw);
     124    return (int)(pszNext - pszRaw);
     125
     126#else /* The same code, just a little more verbose: */
    97127    char *pszEndOfPort = NULL;
    98128    uint16_t u16Port = 0;
     
    105135    AssertReturn(pszRaw[0] == PF_FIELD_SEPARATOR, -1);
    106136
    107     pszRaw++; /* skip line separator */
     137    pszRaw++; /* skip field separator */
    108138    cbRaw --;
    109139
    110     pszEndOfPort = RTStrStr(pszRaw, ":");
     140    char *pszEndOfPort = RTStrStr(pszRaw, ":");
    111141    if (!pszEndOfPort)
    112142    {
     
    146176
    147177     return idxRaw;
     178#endif
    148179}
    149180
注意: 瀏覽 TracChangeset 來幫助您使用更動檢視器

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