[stbsp_sprintf] "%s/%s" crash on armeabi-v7a (32bits) devices, arm64-v8a devices are fine.

Open
#40 3 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
4/5
Estimated time
3-5 days
Newbie friendliness
15/100
Issue type
Bug
Clarity
Needs clarification
Activity status
Stale
Tech stack
c, cpp

Research direction

The crash is a SIGBUS in stbsp_vsprintfcb, reached from stbsp_sprintf, in the single header stb_sprintf.h. Start from the backtrace, then build the repro for armeabi-v7a with -O3 and compare it against the -O0 build, which works. Done means the "%s/%s" call returns "hello/world" on the 32-bit ARM release build without a fault. The issue does not say what to change, so confirm the cause first.

Written by the indexing model from the issue text.

Description

armeabi-v7a (32bits), debug build (-O0), ok
armeabi-v7a (32bits), release build (-O3), crash
arm64-v8a (64bits), debug build (-O0), ok
arm64-v8a (64bits), release build (-O3), ok

build env:

    gradle 4.6
    android-ndk-r20b-x86_64
    armeabi-v7a

test code:

     
        // quick test
	{
		const char *a = "hello";
		const char *b = "world";

		logw("a=%s", a);
		logw("b=%s", b);

		char buf[0x20] = { 0 };
		stbsp_sprintf(buf, "%s/%s", a, b);  // <---- crash on this line

		logw("result:%s", buf);
	}

output:

W/jni     (11770): a=hello
W/jni     (11770): b=world
F/libc    (11770): Fatal signal 7 (SIGBUS) at 0x7a0d1497 (code=1), thread 11770 (main)
D/AEE/AED (  147): $===AEE===AEE===AEE===$	

stack backtrace:

I/DEBUG   (11806): signal 7 (SIGBUS), code 1 (BUS_ADRALN), fault addr 7a0d1497
D/KeyguardViewMediator(  875): setHidden false
D/KeyguardUpdateMonitor(  875): sendKeyguardVisibilityChanged(true)
D/KeyguardUpdateMonitor(  875): handleKeyguardVisibilityChanged(1)
D/KeyguardViewMediator(  875): handleMessage enter msg name=SET_HIDDEN
D/KeyguardViewMediator(  875): handleMessage exit msg name=SET_HIDDEN
I/SurfaceFlinger(  153): [virtual void android::LayerScreenshot::setGeometry(const android::sp<const android::DisplayDevice>&, android::HWComposer::HWCLayerInterface&)] add:716, count:1
D/SurfaceFlinger(  153): [doDisplayComposition] skip composition for [Built-in Screen (type:0)], dirtyRegion empty
I/SurfaceFlinger(  153): [virtual void android::LayerScreenshot::setGeometry(const android::sp<const android::DisplayDevice>&, android::HWComposer::HWCLayerInterface&)] add:716, count:1
D/SurfaceFlinger(  153): [doDisplayComposition] skip composition for [Built-in Screen (type:0)], dirtyRegion empty
I/DEBUG   (11806):     r0 bee42100  r1 7a0d1497  r2 00000005  r3 00000004
I/DEBUG   (11806):     r4 00000005  r5 00000000  r6 bee42100  r7 bee420c0
I/DEBUG   (11806):     r8 00000000  r9 bee42100  sl 00000005  fp 00000005
I/DEBUG   (11806):     ip 00000000  sp bee41e08  lr 00000020  pc 7a02a692  cpsr 20000030
I/DEBUG   (11806): 
I/DEBUG   (11806): backtrace:
I/DEBUG   (11806):     #00  pc 00311692  /data/app-lib/com.company.app-2/libGL2JNI.so (stbsp_vsprintfcb+4817)
I/DEBUG   (11806):     nothings/stb#1  pc 00312219  /data/app-lib/com.company.app-2/libGL2JNI.so (stbsp_sprintf+40)
I/DEBUG   (11806):     nothings/stb#2  pc 001ed7db  /data/app-lib/com.company.app-2/libGL2JNI.so (app::AppImpl::Init(char const*, char const*, char const*)+98)
I/DEBUG   (11806):     nothings/stb#3  pc 002382d9  /data/app-lib/com.company.app-2/libGL2JNI.so (Java_com_company_app_GL2JNILib_nativeOnActivityCreate+172)
I/DEBUG   (11806): 
I/DEBUG   (11806): stack:
I/DEBUG   (11806):          bee41dc8  00000000  
I/DEBUG   (11806):          bee41dcc  78f7a558  
I/DEBUG   (11806):          bee41dd0  40145d60  /system/lib/libc.so
I/DEBUG   (11806):          bee41dd4  7a273000  
I/DEBUG   (11806):          bee41dd8  40145d50  /system/lib/libc.so
I/DEBUG   (11806):          bee41ddc  400f59a0  /system/lib/libc.so (_pthread_internal_add+20)
I/DEBUG   (11806):          bee41de0  78f7a558  
I/DEBUG   (11806):          bee41de4  400f5a60  /system/lib/libc.so (_init_thread+128)
I/DEBUG   (11806):          bee41de8  00004022  
I/DEBUG   (11806):          bee41dec  4010f4e4  /system/lib/libc.so (mmap+92)
I/DEBUG   (11806):          bee41df0  40152af8  
I/DEBUG   (11806):          bee41df4  7a372f00  [stack:11805]
Dominant language
C
Stars
18
Forks
5
Avg merge
1m
Merged PRs (30d)
3

Getting set up

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from nothings/stb_sprintf

All issues in nothings/stb_sprintf

Similar issues

More C issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.