Clone
ixen <ixen@copyhandler.com>
committed
on 27 Mar 08
Bugfix: with null string there was a problem with get_string().
LoggerImprovements + 5 more
ext/libicpf/src/libicpf/cfg.cpp (+9 -5)
580 580 }
581 581
582 582 /** Function retrieves the string value.
583 583 *
584 584 * \param[in] uiProp - property to retrieve the value of
585 585 * \param[in] stIndex - index of the value to retrieve (meaningful only for
586 586 *                                               array-based properties)
587 587 * \return Property value.
588 588 */
589 589 const tchar_t* config::get_string(uint_t uiProp, tchar_t* pszBuffer, size_t stBufferSize, size_t stIndex)
590 590 {
591 591         if(!pszBuffer || stBufferSize < 1)
592 592                 return NULL;
593 593
594 594         m_lock.lock();
595 595         if(uiProp >= m_pvProps->size())
596 596         {
597 597                 m_lock.unlock();
598 598                 THROW(_t("Index out of range"), 0, 0, 0);
599 599         }
  600         size_t stLen = 0;
600 601         const tchar_t* psz=m_pvProps->at(uiProp).get_string(stIndex);
601           size_t stLen = _tcslen(psz);
  602         if(psz)
  603         {
  604                 stLen = _tcslen(psz);
602 605                 if(stLen >= stBufferSize)
603 606                         stLen = stBufferSize - 1;
604 607
605 608                 _tcsncpy(pszBuffer, psz, stLen);
  609         }
606 610         pszBuffer[stLen] = _t('\0');
607 611         m_lock.unlock();
608 612         return pszBuffer;
609 613 }
610 614
611 615 bool config::enum_properties(const tchar_t* pszName, PFNCFGENUMCALLBACK pfn, ptr_t pParam)
612 616 {
613 617         ptr_t pFind = m_pCfgBase->find(pszName);
614 618         if(pFind)
615 619         {
616 620                 PROPINFO pi;
617 621                 while(m_pCfgBase->find_next(pFind, pi))
618 622                 {
619 623                         (*pfn)(pi.bGroup, pi.pszName, pi.pszValue, pParam);
620 624                 }
621 625
622 626                 m_pCfgBase->find_close(pFind);
623 627                 return true;
624 628         }
625 629         else