Thread: Characters seem to be skipped incorrectly

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

    Characters seem to be skipped incorrectly

    I have a function that's meant to read the contents of text literals, somehow or other it seems to be randomly skipping the 1st few characters:
    Struggling to spot the cause myself so hoping fresh eyes can, here's my current output (seems UTF-8 doesn't get copied to the clipboard properly so don't mind the \Uffffffff stuff):
    Code:
    make char.run (in directory: /run/media/zxuiji/ZXUIJI_1TB/github/mc)
    cc -fPIC -Wall -Wno-multichar  -shared -o ./libnext.so -c next.c
    cc -fPIC -Wall -Wno-multichar  -shared -o ./libtsc.so -c tsc.c
    cc -fPIC -Wall -Wno-multichar  -shared -o ./libbase62.so -c base62.c
    cc -fPIC -Wall -Wno-multichar  -D OUT=char.elf -o ./char.elf char.c ./libnext.so ./libtsc.so ./libbase62.so
    ./char.elf
    char.c:551:literalc(): Error: 0x00000054, 84, Invalid or incomplete multibyte or wide character, Info:
    char.c:551:literalc(): Error: 0x00000054, 84, Invalid or incomplete multibyte or wide character, Info:
    std_encoding = 'UTF-8'
    Compiler Tests:
    'abcd': 0x61626364, 'd', dcba
    '\u2ea2': 0x00E2BAA2, '\Uffffffff', \Uffffffff\Uffffffff\Uffffffffa\u2ea2': 0x61E2BAA2, '\Uffffffff', \Uffffffff\Uffffffff\Uffffffff'\u2ea2a': 0xE2BAA261, 'a', a\Uffffffff\Uffffffff\Uffffffffnit tests:
    010 = 8
    0b101 = 5
    99999 = 99999
    0x5f5e0ff = 99999999
    \u2ea2 = 00A2BAE2, '\u2ea2'
    'abcd' = 61626364, 'dcba'
    '\u2ea2' = 00E2BAA2, '\Uffffffff\Uffffffff\Uffffffff'a\u2ea2' = 61E2BAA2, '\Uffffffff\Uffffffff\Uffffffff
    '\u2ea2a' = 00EEA8AA, '\Uffffffff\Uffffffff\Uffffffff"\u2ea2" = 00A2BAE2, '\u2ea2'
    "abcd\u2ea2" = 64636261, 'abcd\u2ea2'
    "\u2ea2abcd" = 62AAA8EE, '\uea2abcd'
    "abcd\u2ea2wxyz" = 64636261, 'abcd\u2ea2wxyz'
    u8\u2ea2 =
    u8'abcd' = 61626364, 'dcba'
    u8'\u2ea2' = 00E2BAA2, '\Uffffffff\Uffffffff\Uffffffffu8'a\u2ea2' = 61E2BAA2, '\Uffffffff\Uffffffff\Uffffffff
    u8'\u2ea2a' = 00EEA8AA, '\Uffffffff\Uffffffff\Uffffffffu8"\u2ea2" = 00A2BAE2, '\u2ea2'
    u8"abcd\u2ea2" = 64636261, 'abcd\u2ea2'
    u8"\u2ea2abcd" = 62AAA8EE, '\uea2abcd'
    u8"abcd\u2ea2wxyz" = 64636261, 'abcd\u2ea2wxyz'
    u\u2ea2 =
    u'abcd' = 0064FEFF, '
    u'\u2ea2' = 00000000, ''
    u'a\u2ea2' = 00000000, ''
    u'\u2ea2a' = 00000000, ''
    u"\u2ea2" = 00002EA2, '
    u"abcd\u2ea2" = 00620061, '
    u"\u2ea2abcd" = 0062EA2A, '
    u"abcd\u2ea2wxyz" = 00620061, '
    U\u2ea2 =
    U'abcd' = 0000FEFF, '
    U'\u2ea2' = 00000000, ''
    U'a\u2ea2' = 00000000, ''
    U'\u2ea2a' = 00000000, ''
    U"\u2ea2" = 00002EA2, '
    U"abcd\u2ea2" = 00000061, '
    U"\u2ea2abcd" = 0000EA2A, '
    U"abcd\u2ea2wxyz" = 00000061, '
    L\u2ea2 =
    L'abcd' =
    L'\u2ea2' =
    L'a\u2ea2' =
    L'\u2ea2a' =
    L"\u2ea2" =
    L"abcd\u2ea2" =
    L"\u2ea2abcd" =
    L"abcd\u2ea2wxyz" =
    User Tests:
    Please enter a character:
    rm libtsc.so libbase62.so char.elf libnext.so
    char.c:551:literalc(): Error: 0x00000054, 84, Invalid or incomplete multibyte or wide character, Info:
    char.c:551:literalc(): Error: 0x00000054, 84, Invalid or incomplete multibyte or wide character, Info:
    char.c:551:literalc(): Error: 0x00000054, 84, Invalid or incomplete multibyte or wide character, Info:
    char.c:551:literalc(): Error: 0x00000054, 84, Invalid or incomplete multibyte or wide character, Info:
    char.c:551:literalc(): Error: 0x00000054, 84, Invalid or incomplete multibyte or wide character, Info:
    char.c:551:literalc(): Error: 0x00000054, 84, Invalid or incomplete multibyte or wide character, Info:
    char.c:551:literalc(): Error: 0x00000054, 84, Invalid or incomplete multibyte or wide character, Info:
    char.c:551:literalc(): Error: 0x00000054, 84, Invalid or incomplete multibyte or wide character, Info:
    char.c:551:literalc(): Error: 0x00000054, 84, Invalid or incomplete multibyte or wide character, Info:
    char.c:551:literalc(): Error: 0x00000054, 84, Invalid or incomplete multibyte or wide character, Info:
    char.c:551:literalc(): Error: 0x00000054, 84, Invalid or incomplete multibyte or wide character, Info:
    Compilation finished successfully.
    Code:
    int rdText( NEXTC *_nextc, char8_t *c, size_t leng, size_t stop, rdTextTok *tok ) {
    	int ret = nextc_validate(_nextc);
    	size_t max;
    	if ( ret != EXIT_SUCCESS ) return ret;
    	if ( !c || !tok ) {
    		ret = EDESTADDRREQ;
    		FAIL( stderr, ret, "c or tok was NULL!");
    		return ret;
    	}
    	if ( !stop ) stop = leng;
    	tok->left = leng - tok->i;
    	if ( tok->now[0] ) {
    		max = utfclen(tok->now[0]) + 1;
    		if ( tok->left < max || stop <= (tok->i + max) )
    			return ERANGE;
    		(void)utfcpy( &c[tok->i], tok->left, tok->now, max );
    		tok->i += max;
    		tok->left -= max;
    		(void)memset( tok->now, 0, NEXTC_C_SIZE );
    	}
    	while ( tok->use_current || (ret = nextc(_nextc)) == EXIT_SUCCESS ) {
    		switch ( _nextc->c[0] ) {
    		case 0: case U'\n': case U'\r':
    			ret = EILSEQ;
    			FAIL( stderr, ret, "special characters"
    				" must be escaped in text literals!");
    			return ret;
    		case U'\\':
    			(void)rdEscChr( _nextc, tok->now );
    			tok->use_current = 1;
    			max = utfclen(tok->now[0]) + 1;
    			if ( tok->left < max || stop <= (tok->i + max) )
    				return ERANGE;
    			(void)utfcpy( &(c[tok->i]), tok->left, tok->now, max );
    			(void)memset( tok->now, 0, NEXTC_C_SIZE );
    			break;
    		case U'\'': case U'"':
    			if ( !(tok->left) ) {
    				tok->use_current = 1;
    				return ERANGE;
    			}
    			tok->use_current = 0;
    			c[tok->i] = 0;
    			return EXIT_SUCCESS;
    		default:
    			max = utfclen(_nextc->c[0]) + 1;
    			if ( tok->left < max || stop <= (tok->i + max) ) {
    				tok->use_current = 1;
    				return ERANGE;
    			}
    			(void)utfcpy( &c[tok->i], tok->left, _nextc->c, max );
    			tok->use_current = 0;
    		}
    		tok->i += max;
    		tok->left = leng - tok->i;
    	}
    	return ret;
    }

  2. #2
    Registered User awsdert's Avatar
    Join Date
    Jan 2015
    Posts
    657
    Found the error, it wasn't directly in rdText, it was in a sub sub call to ubase() via rdEscChr(), I had missed the = sign in a >= comparison for the max number of characters to read as part of the number, rectifying that fixed my output, fresh eyes helped on this occasion

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. gets() skipped!
    By ncode in forum C Programming
    Replies: 14
    Last Post: 02-06-2012, 05:01 PM
  2. Scanf Being skipped
    By GibsMe in forum C Programming
    Replies: 2
    Last Post: 10-11-2009, 03:23 PM
  3. Scanf() skipped
    By new-b in forum C Programming
    Replies: 9
    Last Post: 07-18-2009, 01:34 AM
  4. scanf is being skipped
    By yougene in forum C Programming
    Replies: 6
    Last Post: 12-24-2008, 06:05 AM
  5. Why is this statement being skipped?
    By TalonStriker in forum C Programming
    Replies: 22
    Last Post: 11-12-2007, 05:45 AM

Tags for this Thread