VirtualBox

Changeset 42375 in vbox for trunk/src/VBox


Ignore:
Timestamp:
Jul 25, 2012 7:24:41 AM (13 years ago)
Author:
vboxsync
Message:

Devices/Parallel: Fixing more todos in DrvHostParallel.cpp as identified by Knut and Klaus.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Devices/Parallel/DrvHostParallel.cpp

    r42349 r42375  
    6464
    6565#if defined(VBOX_WITH_WIN_PARPORT_SUP) && defined(IN_RING3)
    66 # include <Windows.h>
    67 # include <setupapi.h>
    68 # include <cfgmgr32.h>
    6966# include <iprt/mem.h>
    7067# include <iprt/string.h>
     
    355352    {
    356353        u32Size = 0;
    357         cmRet = CM_Get_Res_Des_Data_Size((PULONG)(&u32Size), nextLogConf, 0L);
    358         if (cmRet != CR_SUCCESS)
    359         {
    360             CM_Free_Res_Des_Handle(nextLogConf); /** @todo r=bird: Why are you doing this twice in this code path? */
    361             break;
    362         }
    363         pBuf = (uint8_t *)RTMemAlloc(u32Size + 1);
    364         if (!pBuf)
    365         {
    366             CM_Free_Res_Des_Handle(nextLogConf); /** @todo r=bird: Ditto above. */
    367             break;
    368         }
    369         cmRet = CM_Get_Res_Des_Data(nextLogConf, pBuf, u32Size, 0L);
    370         if (cmRet != CR_SUCCESS)
     354        if ((cmRet = CM_Get_Res_Des_Data_Size((PULONG)(&u32Size), nextLogConf, 0L)) != CR_SUCCESS
     355            &&  !(pBuf = (uint8_t *)RTMemAlloc(u32Size + 1))
     356            &&   (cmRet = CM_Get_Res_Des_Data(nextLogConf, pBuf, u32Size, 0L)) != CR_SUCESS
     357            )
    371358        {
    372359            CM_Free_Res_Des_Handle(nextLogConf);
    373             RTMemFree(pBuf);
     360            if (pBuf)
     361                RtMemFree(pBuf);
    374362            break;
     363
    375364        }
    376365        LogFlowFunc(("call GetIOResource\n"));
     
    431420            pBuf = (uint8_t *)RTMemAlloc(dwBufSize * 2);
    432421        }
    433 
    434         if (pBuf) /** @todo r=bird: You're not checking errors here. */
     422        if(!pBuf)
     423            return VERR_NO_MEMORY;
     424
     425        if (RTStrStr((char*)pBuf, "LPT"))
    435426        {
    436              if (RTStrStr((char*)pBuf, "LPT"))
    437              {
    438                  u32ParportAddr = drvHostWinFindIORangeResource(DeviceInfoData.DevInst);
    439                  if (u32ParportAddr)
    440                  {
    441                      /* Find parallel port name and update the shared data struncture */
    442                      char *pCh = RTStrStr((char*)pBuf, "(");
    443                      char *pTmpCh = RTStrStr((char *)pBuf, ")");
    444                      /* check for the confirmation for the availability of parallel port */
    445                      if (!(pCh && pTmpCh))
    446                      {
    447                          LogFlowFunc(("Parallel port Not Found. \n"));
    448                          return VERR_NOT_FOUND;
    449 
    450                      }
    451                      if (((pTmpCh - (char *)pBuf) - (pCh - (char *)pBuf)) < 0) {
    452                          LogFlowFunc(("Parallel port string not properly formatted.\n"));
    453                          return VERR_NOT_FOUND;
    454                      }
    455                      /* check for the confirmation for the availability of parallel port */
    456                      if (RTStrCopyEx((char *)(pThis->szParportName), sizeof(pThis->szParportName),
    457                                       pCh+1, ((pTmpCh - (char *)pBuf) - (pCh - (char *)pBuf)) - 1))
    458                      {
    459                          LogFlowFunc(("Parallel Port Not Found.\n"));
    460                          return VERR_NOT_FOUND;
    461                      }
    462                      *((char *)pThis->szParportName + (pTmpCh - (char *)pBuf) - (pCh - (char *)pBuf) + 1 ) = '\0';
    463 
    464                      /* checking again to make sure that we have got a valid name and in valid format too. */
    465                      if (RTStrNCmp((char *)pThis->szParportName, "LPT", 3)) {
    466                          LogFlowFunc(("Parallel Port name \"LPT\" Not Found.\n"));
    467                          return VERR_NOT_FOUND;
    468                      }
    469 
    470                      if (!RTStrStr((char *)pThis->szParportName, "LPT")
    471                             || !(pThis->szParportName[3] >= '0'
    472                             && pThis->szParportName[3] <= '9'))
    473                      {
    474                          RT_BZERO(pThis->szParportName, sizeof(pThis->szParportName));
    475                          LogFlowFunc(("Printer Port Name Not Found.\n"));
    476                          return VERR_NOT_FOUND;
    477                      }
    478                      pThis->fParportAvail     = true;
    479                      pThis->u32LptAddr        = u32ParportAddr;
    480                      pThis->u32LptAddrControl = pThis->u32LptAddr + CTRL_REG_OFFSET;
    481                      pThis->u32LptAddrStatus  = pThis->u32LptAddr + STATUS_REG_OFFSET;
    482                  }
    483                  if (pThis->fParportAvail)
    484                      break;
    485              }
     427            u32ParportAddr = drvHostWinFindIORangeResource(DeviceInfoData.DevInst);
     428            if (u32ParportAddr)
     429            {
     430                /* Find parallel port name and update the shared data struncture */
     431                char *pCh = RTStrStr((char*)pBuf, "(");
     432                char *pTmpCh = RTStrStr((char *)pBuf, ")");
     433                /* check for the confirmation for the availability of parallel port */
     434                if (!(pCh && pTmpCh))
     435                {
     436                    LogFlowFunc(("Parallel port Not Found. \n"));
     437                    return VERR_NOT_FOUND;
     438
     439                }
     440                if (((pTmpCh - (char *)pBuf) - (pCh - (char *)pBuf)) < 0) {
     441                    LogFlowFunc(("Parallel port string not properly formatted.\n"));
     442                    return VERR_NOT_FOUND;
     443                }
     444                /* check for the confirmation for the availability of parallel port */
     445                if (RTStrCopyEx((char *)(pThis->szParportName), sizeof(pThis->szParportName),
     446                    pCh+1, ((pTmpCh - (char *)pBuf) - (pCh - (char *)pBuf)) - 1))
     447                {
     448                    LogFlowFunc(("Parallel Port Not Found.\n"));
     449                    return VERR_NOT_FOUND;
     450                }
     451                *((char *)pThis->szParportName + (pTmpCh - (char *)pBuf) - (pCh - (char *)pBuf) + 1 ) = '\0';
     452
     453                /* checking again to make sure that we have got a valid name and in valid format too. */
     454                if (RTStrNCmp((char *)pThis->szParportName, "LPT", 3)) {
     455                    LogFlowFunc(("Parallel Port name \"LPT\" Not Found.\n"));
     456                    return VERR_NOT_FOUND;
     457                }
     458                if (!RTStrStr((char *)pThis->szParportName, "LPT")
     459                    || !(pThis->szParportName[3] >= '0'
     460                    && pThis->szParportName[3] <= '9'))
     461                {
     462                    RT_BZERO(pThis->szParportName, sizeof(pThis->szParportName));
     463                    LogFlowFunc(("Printer Port Name Not Found.\n"));
     464                    return VERR_NOT_FOUND;
     465                }
     466                pThis->fParportAvail     = true;
     467                pThis->u32LptAddr        = u32ParportAddr;
     468                pThis->u32LptAddrControl = pThis->u32LptAddr + CTRL_REG_OFFSET;
     469                pThis->u32LptAddrStatus  = pThis->u32LptAddr + STATUS_REG_OFFSET;
     470            }
     471            if (pThis->fParportAvail)
     472                break;
    486473        }
    487474        if (pBuf)
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