VirtualBox

Changeset 18451 in vbox for trunk/src


Ignore:
Timestamp:
Mar 28, 2009 4:04:18 AM (16 years ago)
Author:
vboxsync
Message:

VBoxGuestR3LibGuestProp.cpp: load of size_t warnings. Simplified the parameter setting by adding VbglHGCMParmPtrSetString.

Location:
trunk/src/VBox/Additions/common/VBoxGuestLib
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Additions/common/VBoxGuestLib/VBGLR3Internal.h

    r10797 r18451  
    8181}
    8282
     83
     84#ifdef ___iprt_string_h
     85
     86DECLINLINE(void) VbglHGCMParmPtrSetString(HGCMFunctionParameter *pParm, const char *psz)
     87{
     88    pParm->type                    = VMMDevHGCMParmType_LinAddr;
     89    pParm->u.Pointer.size          = (uint32_t)strlen(psz) + 1;
     90    pParm->u.Pointer.u.linearAddr  = (uintptr_t)psz;
     91}
     92
     93#endif /* ___iprt_string_h */
     94
    8395__END_DECLS
    8496
  • trunk/src/VBox/Additions/common/VBoxGuestLib/VBoxGuestR3LibGuestProp.cpp

    r14359 r18451  
    124124        Msg.hdr.u32Function = SET_PROP_VALUE;
    125125        Msg.hdr.cParms = 3;
    126         VbglHGCMParmPtrSet(&Msg.name, const_cast<char *>(pszName), strlen(pszName) + 1);
    127         VbglHGCMParmPtrSet(&Msg.value, const_cast<char *>(pszValue), strlen(pszValue) + 1);
    128         VbglHGCMParmPtrSet(&Msg.flags, const_cast<char *>(pszFlags), strlen(pszFlags) + 1);
     126        VbglHGCMParmPtrSetString(&Msg.name,  pszName);
     127        VbglHGCMParmPtrSetString(&Msg.value, pszValue);
     128        VbglHGCMParmPtrSetString(&Msg.flags, pszFlags);
    129129        rc = vbglR3DoIOCtl(VBOXGUEST_IOCTL_HGCM_CALL(sizeof(Msg)), &Msg, sizeof(Msg));
    130130        if (RT_SUCCESS(rc))
     
    139139        Msg.hdr.u32Function = DEL_PROP;
    140140        Msg.hdr.cParms = 1;
    141         VbglHGCMParmPtrSet(&Msg.name, const_cast<char *>(pszName), strlen(pszName) + 1);
     141        VbglHGCMParmPtrSetString(&Msg.name, pszName);
    142142        rc = vbglR3DoIOCtl(VBOXGUEST_IOCTL_HGCM_CALL(sizeof(Msg)), &Msg, sizeof(Msg));
    143143        if (RT_SUCCESS(rc))
     
    173173        Msg.hdr.u32Function = SET_PROP_VALUE;
    174174        Msg.hdr.cParms = 2;
    175         VbglHGCMParmPtrSet(&Msg.name, const_cast<char *>(pszName), strlen(pszName) + 1);
    176         VbglHGCMParmPtrSet(&Msg.value, const_cast<char *>(pszValue), strlen(pszValue) + 1);
     175        VbglHGCMParmPtrSetString(&Msg.name, pszName);
     176        VbglHGCMParmPtrSetString(&Msg.value, pszValue);
    177177        rc = vbglR3DoIOCtl(VBOXGUEST_IOCTL_HGCM_CALL(sizeof(Msg)), &Msg, sizeof(Msg));
    178178        if (RT_SUCCESS(rc))
     
    187187        Msg.hdr.u32Function = DEL_PROP;
    188188        Msg.hdr.cParms = 1;
    189         VbglHGCMParmPtrSet(&Msg.name, const_cast<char *>(pszName), strlen(pszName) + 1);
     189        VbglHGCMParmPtrSetString(&Msg.name, pszName);
    190190        rc = vbglR3DoIOCtl(VBOXGUEST_IOCTL_HGCM_CALL(sizeof(Msg)), &Msg, sizeof(Msg));
    191191        if (RT_SUCCESS(rc))
     
    281281    Msg.hdr.u32Function = GET_PROP;
    282282    Msg.hdr.cParms = 4;
    283     VbglHGCMParmPtrSet(&Msg.name, const_cast<char *>(pszName), strlen(pszName) + 1);
     283    VbglHGCMParmPtrSetString(&Msg.name, pszName);
    284284    VbglHGCMParmPtrSet(&Msg.buffer, pvBuf, cbBuf);
    285285    VbglHGCMParmUInt64Set(&Msg.timestamp, 0);
     
    442442                                         uint32_t *pcchValueActual)
    443443{
    444     char *pcBuf = NULL;
    445     int rc = VbglR3GuestPropReadValueAlloc(u32ClientId, pszName, &pcBuf);
     444    char *pszBuf = NULL;
     445    int rc = VbglR3GuestPropReadValueAlloc(u32ClientId, pszName, &pszBuf);
    446446    if (RT_SUCCESS(rc))
    447447    {
    448         uint32_t cchValueActual = strlen(pcBuf) + 1;
    449         if (cchValueActual > cchValue)
     448        size_t cchValueActual = strlen(pszBuf) + 1;
     449        if (cchValueActual <= cchValue)
     450            memcpy(pszValue, pszBuf, cchValueActual);
     451        else
    450452        {
    451453            if (pcchValueActual != NULL)
    452                 *pcchValueActual = cchValueActual;
     454                *pcchValueActual = (uint32_t)cchValueActual;
    453455            rc = VERR_BUFFER_OVERFLOW;
    454456        }
    455         if (RT_SUCCESS(rc))
    456             strcpy(pszValue, pcBuf);
    457     }
    458     VbglR3GuestPropReadValueFree(pcBuf);
     457    }
     458    VbglR3GuestPropReadValueFree(pszBuf);
    459459    return rc;
    460460}
     
    495495    Msg.hdr.cParms = 3;
    496496    /* Get the length of the patterns array... */
    497     uint32_t cchPatterns = 0;
    498     for (uint32_t cchCurrent = strlen(pszzPatterns); cchCurrent != 0;
     497    size_t cchPatterns = 0;
     498    for (size_t cchCurrent = strlen(pszzPatterns); cchCurrent != 0;
    499499         cchCurrent = strlen(pszzPatterns + cchPatterns))
    500500        cchPatterns += cchCurrent + 1;
    501501    /* ...including the terminator. */
    502502    ++cchPatterns;
    503     VbglHGCMParmPtrSet(&Msg.patterns, const_cast<char *>(pszzPatterns),
    504                        cchPatterns);
     503    VbglHGCMParmPtrSet(&Msg.patterns, (char *)pszzPatterns, (uint32_t)cchPatterns);
    505504    VbglHGCMParmPtrSet(&Msg.strings, pcBuf, cbBuf);
    506505    VbglHGCMParmUInt32Set(&Msg.size, 0);
     
    570569
    571570    /* Get the length of the pattern string, including the final terminator. */
    572     uint32_t cchPatterns = 1;
    573     for (unsigned i = 0; i < cPatterns; ++i)
     571    size_t cchPatterns = 1;
     572    for (uint32_t i = 0; i < cPatterns; ++i)
    574573        cchPatterns += strlen(papszPatterns[i]) + 1;
    575574
     
    577576    RTMemAutoPtr<char> Patterns;
    578577    Patterns = (char *)RTMemAlloc(cchPatterns);
    579     uint32_t iOffs = 0;
     578    size_t off = 0;
    580579    for (uint32_t i = 0; i < cPatterns; ++i)
    581580    {
    582         uint32_t cb = strlen(papszPatterns[i]) + 1;
    583         memcpy(&Patterns[iOffs], papszPatterns[i], cb);
    584         iOffs += cb;
    585     }
    586     Patterns[iOffs] = '\0';
     581        size_t cb = strlen(papszPatterns[i]) + 1;
     582        memcpy(&Patterns[off], papszPatterns[i], cb);
     583        off += cb;
     584    }
     585    Patterns[off] = '\0';
    587586
    588587    /* Randomly chosen initial size for the buffer to hold the enumeration
     
    841840    Msg.hdr.info.u32Function = GET_NOTIFICATION;
    842841    Msg.hdr.info.cParms = 4;
    843     Msg.patterns.SetPtr(const_cast<char *>(pszPatterns),
    844                         strlen(pszPatterns) + 1);
     842    VbglHGCMParmPtrSetString(&Msg.patterns, pszPatterns);
    845843    Msg.buffer.SetPtr(pvBuf, cbBuf);
    846844    Msg.timestamp.SetUInt64(u64Timestamp);
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