Thread: printf specifier readers reaching a segfault

  1. #1
    Registered User awsdert's Avatar
    Join Date
    Jan 2015
    Posts
    1,733

    printf specifier readers reaching a segfault

    I'm struggling to spot the cause of the segfault, I only know that somehow or other the 2 values before it are not read as expected

    This is the pointer that receives 0x1 somehow which triggers a segfault during the attempt to
    read it, it's pass %s as it's specifier:
    src/libpaw/std/putstr.c * 8ff0a3bf35930d1b736960d283586c045f0f23ad * Lee Shallis / Dragonbuilder * GitLab

    This is the function that should've read the 2 values before:
    src/libpaw/std/putnum.c * 8ff0a3bf35930d1b736960d283586c045f0f23ad * Lee Shallis / Dragonbuilder * GitLab

    And this is the root calling function of my printf handler:
    src/libpaw/std/printf.c * 8ff0a3bf35930d1b736960d283586c045f0f23ad * Lee Shallis / Dragonbuilder * GitLab

    Any help is appreciated, currently I'm suspecting this function is the root of the problem:
    src/libpaw/std/printf.c * 8ff0a3bf35930d1b736960d283586c045f0f23ad * Lee Shallis / Dragonbuilder * GitLab

    Since the values before have this specifier %4d and %d is read correctly in earlier tests so I can only suspect that one function.

  2. #2
    Registered User awsdert's Avatar
    Join Date
    Jan 2015
    Posts
    1,733
    Okay, def was the problem function, wasn't returning the count of characters read, also I think there were some bugs in it so I re-worked it, doesn't seem to input the width though which is a problem:
    Code:
    PAW_API pawd pawva_option_dig( PAWVA_CONFIG *data, pawhhs args, va_list *va )
    {
    	pawd	dot	= data->opt & PAWVA_O_PERIOD;
    	pawd	pad0	= (*args == '0') ? '0' : 0;
    	pawd	*ptr	= &(data->min.len);
    	pawd	skip	= (pad0 && dot);
    	pawd	len	= skip;
    	pawsu	str	= {""};
    
    	for ( ; args[len] >= '0' && args[len] <= '9'; ++len )
    		str.str[len-skip] = args[len];
    
    	if ( dot )
    		ptr = &(data->max);
    	else if ( pad0 )
    		data->min.txt = '0';
    
    	*ptr = paws2u( &str, 10, PAW_BASE10_REM );
    	(void)va;
    	return len;
    }
    Edit: I suppose the other potential cause of the width failing to get through is these 2 which the joining functions pass off to after doing the bare minimum:
    Code:
    PAW_API pawd pawva_putf_calc_ins( PAWVA_CONFIG *data, pawd need )
    {
    	/* Align in center */
    	if ( data->mov == 0 )
    		data->insert = data->append = (need / 2) + !!(need % 2);
    	/* Align on the left */
    	else if ( data->mov < 0 )
    	{
    		data->insert = 0;
    		data->append = need;
    	}
    	/* Align on the right */
    	else
    	{
    		data->insert = need;
    		data->append = 0;
    	}
    
    	return need;
    }
    
    PAW_API pawd pawva_putf_aligntxt
    	( PAWVA_CONFIG *data, pawSTR Str, pawd was, pawd did )
    {
    	pawd need = data->min.len - did;
    	if ( need > 0 )
    	{
    		pawhhc *txt = PawTopOfString(Str);
    		pawhhc *ins = txt + was, *mid, *add;
    		pawd i = 0;
    
    		pawva_putf_calc_ins( data, need );
    		mid = ins + data->insert;
    		add = mid + did;
    
    		if ( data->insert > 0 )
    		{
    			paw_mov( mid, ins, data->insert * sizeof(pawhhc) );
    			for ( i = 0; i < data->insert; ++i )
    				ins[i] = data->min.txt;
    		}
    		for ( i = 0; i < data->append; ++i )
    			add[i] = data->min.txt;
    		did += data->insert + data->append;
    	}
    	pawSizeStringc( Str, was + did );
    	return did;
    }

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. printf() specifier conversation
    By GokhanK in forum C Programming
    Replies: 17
    Last Post: 03-18-2014, 07:39 PM
  2. bu_log() width specifier does not align like in printf
    By Nyah Check in forum C Programming
    Replies: 8
    Last Post: 04-19-2013, 01:14 PM
  3. printf format specifier padding
    By Blasz in forum C Programming
    Replies: 3
    Last Post: 07-08-2010, 11:26 PM
  4. multiply sections of printf format specifier?
    By space_ferret in forum C Programming
    Replies: 14
    Last Post: 03-27-2009, 10:54 AM
  5. use of printf prevents segfault!
    By MK27 in forum C Programming
    Replies: 31
    Last Post: 08-27-2008, 12:38 PM

Tags for this Thread