Thread: Quick check for potential problems

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Registered User awsdert's Avatar
    Join Date
    Jan 2015
    Posts
    1,735

    Quick check for potential problems

    While I'm waiting on a response in another thread I'll quickly ask if anyone sees any potential problems with this freshly made code:
    Code:
    int alu_mov( alu_t *alu, uintptr_t num, uintptr_t val, size_t size )
    {
    	int ret = 0;
    	void *dst, *src;
    	
    	if ( num >= ALU_REG_ID_LIMIT )
    	{		
    		if ( val >= ALU_REG_ID_LIMIT )
    		{
    			errno = 0;
    			(void)memmove( (void*)num, (void*)val, size );
    			ret = errno;
    			return ret;
    		}
    		
    		ret = _alu_check2( alu, ALU_REG_ID_NEED, val );
    		
    		if ( ret != 0 )
    		{
    			alu_error( ret );
    			return ret;
    		}
    		
    		dst = (void*);
    		src = (alu->regv + val)->part;
    		
    		goto copy;
    	}
    	
    	ret = _alu_check1( alu, num );
    	
    	if ( size > alu->buff.perN )
    		size = alu->buff.perN;
    		
    	dst = (alu->regv + num)->part;
    	src = (void*)val;
    	
    	copy:
    	errno = 0;
    	(void)memset( dst, 0, size );
    	ret = errno;
    	
    	if ( ret != 0 )
    	{
    		alu_error( ret );
    		return ret;
    	}
    	
    	if ( size > alu->buff.perN )
    		size = alu->buff.perN;
    		
    	errno = 0;
    	(void)memmove( dst, src, size );
    	ret = errno;
    	
    	if ( ret != 0 )
    		alu_error( ret );
    	
    	return ret;
    }
    Personally I don't but never hurts to ask for 2nd opinion

    Edit: Just spotted the
    Code:
    		dst = (void*);
    line, rectified in file, left here for future readers
    Last edited by awsdert; 08-09-2020 at 01:42 PM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Quick program check
    By Nik635 in forum C Programming
    Replies: 1
    Last Post: 09-17-2015, 08:20 AM
  2. Quick check
    By SofaWolf in forum C Programming
    Replies: 6
    Last Post: 06-26-2012, 12:53 PM
  3. potential problems?
    By deepcode in forum C Programming
    Replies: 4
    Last Post: 08-11-2010, 02:04 PM
  4. Need a quick check
    By Aliaks in forum C++ Programming
    Replies: 7
    Last Post: 06-05-2009, 04:57 AM
  5. Quick check on reading in + using strings
    By advancedk in forum C Programming
    Replies: 2
    Last Post: 12-08-2008, 10:12 PM

Tags for this Thread