CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 6 of 6
  1. #1
    Join Date
    May 2015
    Posts
    500

    memory allocation related

    Hi,

    Code:
    typedef struct structAuthDelivery
    {
    	u32			nSig;				// For message integrity purposes.
    	AuthSetRes 	eRes;
    	char			pzIMSI[20];
    	u32			nMMHandle;
    	u32			nNumVectors;
    } AuthDelivery;
    
    
    function()
    {
    	    CSignal sSig;
    		
    		AuthDelivery * pAuth = (AuthDelivery*)(sSig.Alloc(0));
    		
    		if (pAuthInfo)
    		{
    			list<CDiaAVP *>	lGroup;
    			if (m_eRATType == RANTypeEUTRAN || m_eRATType == RANTypeIMS)
    			{
    				pAuthInfo->FindAllSameAVPs(DiameterVendorId3GPP, AVP3GPP_EUTRANVector, lGroup);
    			}
    			else
    			{
    				pAuthInfo->FindAllSameAVPs(DiameterVendorId3GPP, AVP3GPP_UTRANVector, lGroup);
    			}
    
    			LogTrace(<< "Auth info contained num of vectors: " << lGroup.size())
    
    			list<CDiaAVP*>::iterator iIter = lGroup.begin();
    			while (nNumVectors < 5 && iIter != lGroup.end())
    			{
    				CDiaAVP * pAuthvector = *iIter;
    				CDiaAVP * pField = pAuthvector->FindAVP(DiameterVendorId3GPP, AVP3GPP_RAND);
    
    				if (pField)
    				{
    					if (pField->GetOctetStringLen() >= 16)
    					{
    						
    						AuthVector	pVector = (AuthVector*)(((u8*)pAuth) + sizeof(AuthDelivery));
    
    						memcpy((void *)&(pVector->aRAND[0]), pField->GetOctetStringPtr(), 16);
    					}
    				}
    				
    				:
    				nNumVectors++;
    				iIter++;
    			}
    			
    			pAuth->nNumVectors = nNumVectors;
    		}
    		
    		sSig.Post(SigMsgAuthDelivery, m_sDeliveryAddr, SigAddr(SigModDiaConn, 0));
    }
    Currently I am trying to change the above pseudocode (legacy), based on flag, i either fill the sSig Or a new struct.

    Code:
    function()
    {
    	    CSignal sSig;
    	
        // new flag m_bFromAdmin
    	if(m_bFromAdmin)
    	{
    		AuthDelivery sAuthDel;
    		AuthDelivery * pAuth = &sAuthDel;
    	}
    	else
    	{
    		AuthDelivery * pAuth = (AuthDelivery*)(sSig.Alloc(0));
    		pAuth->nSig = AuthDeliverySig;
    		pAuth->eRes = m_bDoingResync?AuthSetResResyncOk:AuthSetResOk;
    		pAuth->nMMHandle = m_sDeliveryAddr.second;
    		strcpy(pAuth->pzIMSI, m_sIMSI.c_str());
    	}
    		
    		if (pAuthInfo)
    		{
    			list<CDiaAVP *>	lGroup;
    			if (m_eRATType == RANTypeEUTRAN || m_eRATType == RANTypeIMS)
    			{
    				pAuthInfo->FindAllSameAVPs(DiameterVendorId3GPP, AVP3GPP_EUTRANVector, lGroup);
    			}
    			else
    			{
    				pAuthInfo->FindAllSameAVPs(DiameterVendorId3GPP, AVP3GPP_UTRANVector, lGroup);
    			}
    
    			LogTrace(<< "Auth info contained num of vectors: " << lGroup.size())
    
    			list<CDiaAVP*>::iterator iIter = lGroup.begin();
    			while (nNumVectors < 5 && iIter != lGroup.end())
    			{
    				CDiaAVP * pAuthvector = *iIter;
    				CDiaAVP * pField = pAuthvector->FindAVP(DiameterVendorId3GPP, AVP3GPP_RAND);
    
    				if (pField)
    				{
    					if (pField->GetOctetStringLen() >= 16)
    					{
    						
    						AuthVector * pVector;
    
    						if(m_bFromAdmin)
    						{
    						    // Best way to allocate this memory, so pVector now holds the first vector 
    							pVector =  ;
    						}
    						else
    						{
    							pVector = (AuthVector*)(((u8*)pAuth) + sizeof(AuthDelivery));
    						}
    
    						memcpy((void *)&(pVector->aRAND[0]), pField->GetOctetStringPtr(), 16);
    					}
    				}
    				
    				:
    				nNumVectors++;
    				iIter++;
    			}
    			
    			pAuth->nNumVectors = nNumVectors;
    		}
    		
    		if(m_bFromAdmin)
    		{
    			CGetSubsInfoVLR::HandleAuthVectorResponse(m_req, m_sIMSI, m_sUniqueId, pAuth, VLRQueryRespSuccess, DataType4G);
    		}
    		else
    		{
    
    		   sSig.Post(SigMsgAuthDelivery, m_sDeliveryAddr, SigAddr(SigModDiaConn, 0));
    		}
    }

  2. #2
    2kaud's Avatar
    2kaud is offline Super Moderator Power Poster
    Join Date
    Dec 2012
    Location
    England
    Posts
    7,822

    Re: memory allocation related

    Code:
    	if (m_bFromAdmin)
    	{
    		AuthDelivery sAuthDel;
    		AuthDelivery * pAuth = &sAuthDel;
    	} else
    ...
    Why have this - when sAuthDel and pAuth are only valid within the {..} scope and aren't used before they go out of scope?
    All advice is offered in good faith only. All my code is tested (unless stated explicitly otherwise) with the latest version of Microsoft Visual Studio (using the supported features of the latest standard) and is offered as examples only - not as production quality. I cannot offer advice regarding any other c/c++ compiler/IDE or incompatibilities with VS. You are ultimately responsible for the effects of your programs and the integrity of the machines they run on. Anything I post, code snippets, advice, etc is licensed as Public Domain https://creativecommons.org/publicdomain/zero/1.0/ and can be used without reference or acknowledgement. Also note that I only provide advice and guidance via the forums - and not via private messages!

    C++23 Compiler: Microsoft VS2022 (17.6.5)

  3. #3
    Join Date
    May 2015
    Posts
    500

    Re: memory allocation related

    Quote Originally Posted by 2kaud View Post
    Code:
    	if (m_bFromAdmin)
    	{
    		AuthDelivery sAuthDel;
    		AuthDelivery * pAuth = &sAuthDel;
    	} else
    ...
    Why have this - when sAuthDel and pAuth are only valid within the {..} scope and aren't used before they go out of scope?
    yes, sorry, it was typo in my pseudocode. It can be changed to something like

    AuthDelivery sAuthDel;
    AuthDelivery * pAuth;
    if (m_bFromAdmin)
    {
    AuthDelivery * pAuth = &sAuthDel;
    } else

  4. #4
    2kaud's Avatar
    2kaud is offline Super Moderator Power Poster
    Join Date
    Dec 2012
    Location
    England
    Posts
    7,822

    Re: memory allocation related

    // Best way to allocate this memory, so pVector now holds the first vector
    pVector = ;
    First vector of what? If not bFromAdmin then pVector points to index 1 from pAuth (second entry). But if bFromAdmin is true then pAuth just points to the memory for sAuthDev which is *AuthDelivery. What is the relation between AuthDelivery and AuthVector? Is AuthVector an array of AuthDelivery?
    All advice is offered in good faith only. All my code is tested (unless stated explicitly otherwise) with the latest version of Microsoft Visual Studio (using the supported features of the latest standard) and is offered as examples only - not as production quality. I cannot offer advice regarding any other c/c++ compiler/IDE or incompatibilities with VS. You are ultimately responsible for the effects of your programs and the integrity of the machines they run on. Anything I post, code snippets, advice, etc is licensed as Public Domain https://creativecommons.org/publicdomain/zero/1.0/ and can be used without reference or acknowledgement. Also note that I only provide advice and guidance via the forums - and not via private messages!

    C++23 Compiler: Microsoft VS2022 (17.6.5)

  5. #5
    Join Date
    May 2015
    Posts
    500

    Re: memory allocation related

    @kaud: thanks a lot for the response .

    Legacy code they use the "AuthVector" after the "Authdelivery". Lets say Authdelivery has nNumVectors =2. There will be two Authvector structs after the Auth delivery.

    Like in the handler for this response is somewhat like this:

    Code:
    void CGetSubsInfoVLR::HandleAuthVectorResponse(Quortus::Oam2::IRequestPtr const &req, const std::string& sIMSI, const std::string& sUniqueId, AuthDelivery * pAuthDel, VLRQueryResponse eVLRQueryResponse, AuthVectorDataType eRATType)
    {
    		if(pAuthDel->eRes == AuthSetResOk && eVLRQueryResponse == VLRQueryRespSuccess)
    		{
    			AuthVector * pVector = (AuthVector*)(((u8*)pAuthDel) + sizeof(AuthDelivery));
    
    			for (u8 nI = 0; nI < pAuthDel->nNumVectors && nI < 10; nI++, pVector++)
    			{
    				LogTraceS("HandleAuthVectorResponse",<< "Vector[" << (u16) nI << "]: " << " bIsQuintuplet: " << pVector->bIsQuintuplet);
    
    				OAM::Data::VLR::Summary data;
    
    				COctetArrayType sRand(pVector->aRAND, nRAND_SIZE);
                            }
                 }
    Last edited by pdk5; February 21st, 2018 at 04:04 AM.

  6. #6
    Join Date
    May 2015
    Posts
    500

    Re: memory allocation related

    @ kaud: It looks like error in the legacy code, as it looks like overwrites the auth vectors when they are more than one. I think it was tested only with one vector.
    I changed the numVectors to 1 and the response fields were ok.

    Now i need to find out the better way of passing the multiple auth vectors back to handler.

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured