VirtualBox

儲存庫 vbox 的更動 18453


忽略:
時間撮記:
2009-3-28 上午04:27:36 (16 年 以前)
作者:
vboxsync
訊息:

GuestPropterties/service.cpp: size_t warnings.
Tip: The readbility of the code would benifit enormously by *not* prefixing every statement with 'if (RT_SUCCESS(rc))', just omitting it where it's not necessary would be a great improvement. ;-)

檔案:
修改 1 筆資料

圖例:

未更動
新增
刪除
  • trunk/src/VBox/HostServices/GuestProperties/service.cpp

    r15277 r18453  
    528528    char *pchBuf;
    529529    uint32_t cchName, cchBuf;
    530     uint32_t cchFlags, cchBufActual;
    531530    char szFlags[MAX_FLAGS_LEN];
    532531
     
    540539       )
    541540        rc = VERR_INVALID_PARAMETER;
    542     if (RT_SUCCESS(rc))
     541    else
    543542        rc = validateName(pcszName, cchName);
    544543
     
    549548    /* Get the value size */
    550549    PropertyList::const_iterator it;
    551     bool found = false;
    552     if (RT_SUCCESS(rc))
     550    if (RT_SUCCESS(rc))
     551    {
     552        rc = VERR_NOT_FOUND;
    553553        for (it = mProperties.begin(); it != mProperties.end(); ++it)
    554554            if (it->mName.compare(pcszName) == 0)
    555555            {
    556                 found = true;
     556                rc = VINF_SUCCESS;
    557557                break;
    558558            }
    559     if (RT_SUCCESS(rc) && !found)
    560         rc = VERR_NOT_FOUND;
     559    }
    561560    if (RT_SUCCESS(rc))
    562561        rc = writeFlags(it->mFlags, szFlags);
    563562    if (RT_SUCCESS(rc))
    564         cchFlags = strlen(szFlags);
    565     /* Check that the buffer is big enough */
    566     if (RT_SUCCESS(rc))
    567     {
    568         cchBufActual = it->mValue.size() + 1 + cchFlags;
    569         paParms[3].setUInt32 (cchBufActual);
    570     }
    571     if (RT_SUCCESS(rc) && (cchBufActual > cchBuf))
    572         rc = VERR_BUFFER_OVERFLOW;
    573     /* Write the value, flags and timestamp */
    574     if (RT_SUCCESS(rc))
    575     {
    576         it->mValue.copy(pchBuf, cchBuf, 0);
    577         pchBuf[it->mValue.size()] = '\0'; /* Terminate the value */
    578         strcpy(pchBuf + it->mValue.size() + 1, szFlags);
    579         paParms[2].setUInt64 (it->mTimestamp);
    580     }
    581 
    582     /*
    583      * Done!  Do exit logging and return.
    584      */
    585     if (RT_SUCCESS(rc))
    586         Log2(("Queried string %s, value=%s, timestamp=%lld, flags=%s\n",
    587               pcszName, it->mValue.c_str(), it->mTimestamp, szFlags));
     563    {
     564        /* Check that the buffer is big enough */
     565        size_t cchBufActual = it->mValue.size() + 1 + strlen(szFlags);
     566        paParms[3].setUInt32 ((uint32_t)cchBufActual);
     567        if (cchBufActual <= cchBuf)
     568        {
     569            /* Write the value, flags and timestamp */
     570            it->mValue.copy(pchBuf, cchBuf, 0);
     571            pchBuf[it->mValue.size()] = '\0'; /* Terminate the value */
     572            strcpy(pchBuf + it->mValue.size() + 1, szFlags);
     573            paParms[2].setUInt64 (it->mTimestamp);
     574
     575            /*
     576             * Done!  Do exit logging and return.
     577             */
     578            Log2(("Queried string %s, value=%s, timestamp=%lld, flags=%s\n",
     579                  pcszName, it->mValue.c_str(), it->mTimestamp, szFlags));
     580        }
     581        else
     582            rc = VERR_BUFFER_OVERFLOW;
     583    }
     584
    588585    LogFlowThisFunc(("rc = %Rrc\n", rc));
    589586    return rc;
     
    839836    if (RT_SUCCESS(rc))
    840837    {
    841         paParms[2].setUInt32 (buffer.size());
     838        paParms[2].setUInt32 ((uint32_t)buffer.size());
    842839        /* Copy the memory if it fits into the guest buffer */
    843840        if (buffer.size() <= cchBuf)
     
    908905    {
    909906        paParms[1].setUInt64(u64Timestamp);
    910         paParms[3].setUInt32(buffer.size());
     907        paParms[3].setUInt32((uint32_t)buffer.size());
    911908        if (buffer.size() <= cchBuf)
    912909            buffer.copy(pchBuf, cchBuf);
     
    13661363    return rc;
    13671364}
     1365
注意: 瀏覽 TracChangeset 來幫助您使用更動檢視器

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