0

This is what I am trying to do:

static char* callerURI; //declared globally
strcpy(callerURI, reqParticipants.URI[idUser]);

Where :

@var VidyoClientRequestParticipants::URI [out]
    Array of values for Vidyo URI of remote participants in a conference.

I get this from a SDK so not sure what it is.

If I log: LOGI("VIDYO_CLIENT_OUT_EVENT_VIDEO_FRAME_RECEIVED AskViewType callerURI 1 REAL: %s" ,reqParticipants.URI[idUser]); I will get a string.

Now if I do:

callerURI = reqParticipants.URI[idUser];

This will work, and will set that String to my callerURI, but it gets unassigned somehow. So I assumed strcpy is the right way to do this. But trying strcpy(callerURI, reqParticipants.URI[idUser]); results in this error:

06-13 05:14:08.044: E/SQLiteDatabase(1165): Error inserting value=true key=com.vidyo.vidyomod
06-13 05:14:08.044: E/SQLiteDatabase(1165): android.database.sqlite.SQLiteException: no such table: KeyValueMap (code 1): , while compiling: INSERT INTO KeyValueMap(value,key) VALUES (?,?)
06-13 05:14:08.044: E/SQLiteDatabase(1165):     at android.database.sqlite.SQLiteConnection.nativePrepareStatement(Native Method)
06-13 05:14:08.044: E/SQLiteDatabase(1165):     at android.database.sqlite.SQLiteConnection.acquirePreparedStatement(SQLiteConnection.java:889)
06-13 05:14:08.044: E/SQLiteDatabase(1165):     at android.database.sqlite.SQLiteConnection.prepare(SQLiteConnection.java:500)
06-13 05:14:08.044: E/SQLiteDatabase(1165):     at android.database.sqlite.SQLiteSession.prepare(SQLiteSession.java:588)
06-13 05:14:08.044: E/SQLiteDatabase(1165):     at android.database.sqlite.SQLiteProgram.<init>(SQLiteProgram.java:58)
06-13 05:14:08.044: E/SQLiteDatabase(1165):     at android.database.sqlite.SQLiteStatement.<init>(SQLiteStatement.java:31)
06-13 05:14:08.044: E/SQLiteDatabase(1165):     at     android.database.sqlite.SQLiteDatabase.insertWithOnConflict(SQLiteDatabase.java:1467)
06-13 05:14:08.044: E/SQLiteDatabase(1165):     at android.database.sqlite.SQLiteDatabase.insert(SQLiteDatabase.java:1339)
06-13 05:14:08.044: E/SQLiteDatabase(1165):     at com.jb.ga0.commerce.util.io.DataBaseHelper.insert(ZeroCamera:323)
06-13 05:14:08.044: E/SQLiteDatabase(1165):     at com.jiubang.commerce.tokencoin.database.d.a(KeyValueMapTable.java:47)
06-13 05:14:08.044: E/SQLiteDatabase(1165):     at com.jiubang.commerce.tokencoin.integralwall.c$1.onAppUninstalled(AppAdsDataManager.java:101)
06-13 05:14:08.044: E/SQLiteDatabase(1165):     at com.jb.ga0.commerce.util.observer.AppChangeObserver.notifyAppUninstalled(ZeroCamera:129)
06-13 05:14:08.044: E/SQLiteDatabase(1165):     at com.jb.ga0.commerce.util.observer.AppChangeObserver.onReceive(ZeroCamera:158)
06-13 05:14:08.044: E/SQLiteDatabase(1165):     at com.jb.ga0.commerce.util.observer.AppChangeObserver.access$100(ZeroCamera:18)
06-13 05:14:08.044: E/SQLiteDatabase(1165):     at com.jb.ga0.commerce.util.observer.AppChangeObserver$AppChangedReceiver.onReceive(ZeroCamera:215)
06-13 05:14:08.044: E/SQLiteDatabase(1165):     at android.app.LoadedApk$ReceiverDispatcher$Args.run(LoadedApk.java:768)
06-13 05:14:08.044: E/SQLiteDatabase(1165):     at android.os.Handler.handleCallback(Handler.java:733)
06-13 05:14:08.044: E/SQLiteDatabase(1165):     at android.os.Handler.dispatchMessage(Handler.java:95)
06-13 05:14:08.044: E/SQLiteDatabase(1165):     at android.os.Looper.loop(Looper.java:136)
06-13 05:14:08.044: E/SQLiteDatabase(1165):     at android.app.ActivityThread.main(ActivityThread.java:5017)
06-13 05:14:08.044: E/SQLiteDatabase(1165):     at java.lang.reflect.Method.invokeNative(Native Method)
06-13 05:14:08.044: E/SQLiteDatabase(1165):     at java.lang.reflect.Method.invoke(Method.java:515)
06-13 05:14:08.044: E/SQLiteDatabase(1165):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:794)
06-13 05:14:08.044: E/SQLiteDatabase(1165):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:610)
06-13 05:14:08.044: E/SQLiteDatabase(1165):     at dalvik.system.NativeStart.main(Native Method)

EDIT:

I have tried this:

 LOGI("VIDYO_CLIENT_OUT_EVENT_VIDEO_FRAME_RECEIVED AskViewType callerURI 1 REAL: %s" ,reqParticipants.URI[idUser]);
char* callerTemp = reqParticipants.URI[idUser];
LOGI("VIDYO_CLIENT_OUT_EVENT_VIDEO_FRAME_RECEIVED AskViewType callerURI 12 REAL: %s" ,callerTemp);
LOGI("VIDYO_CLIENT_OUT_EVENT_VIDEO_FRAME_RECEIVED AskViewType callerURI 13 REAL: %s" ,strlen(callerTemp));
*callerURI= (char *) malloc(sizeof(char *) * (strlen(callerTemp) + 1 ));
strcpy(callerURI, reqParticipants.URI[idUser]);
LOGI("VIDYO_CLIENT_OUT_EVENT_VIDEO_FRAME_RECEIVED AskViewType callerURI 2 REAL: %s" ,reqParticipants.URI[idUser]);
LOGI("VIDYO_CLIENT_OUT_EVENT_VIDEO_FRAME_RECEIVED AskViewType callerURI 2 : %s" ,callerURI);

But I only this gets logged:

06-13 05:40:27.294: I/VidyoMobile app/src/main/jni/ndkVidyoSample.c(19744): VIDYO_CLIENT_OUT_EVENT_VIDEO_FRAME_RECEIVED AskViewType callerURI 1 REAL: scip:CsAPI1528869039-4c6-42722300022166be-d30ff886a73e0ebc;transport=TLS
06-13 05:40:27.294: I/VidyoMobile app/src/main/jni/ndkVidyoSample.c(19744): VIDYO_CLIENT_OUT_EVENT_VIDEO_FRAME_RECEIVED AskViewType callerURI 12 REAL: scip:CsAPI1528869039-4c6-42722300022166be-d30ff886a73e0ebc;transport=TLS

So also strlen() crashes for some reason. Why is this?

rosu alin
  • 5,674
  • 11
  • 69
  • 150
  • 1
    Did you allocated memory? `char *callerURI= (char *) malloc(sizeof(char *) * THE_SIZE); strcpy(callerURI, reqParticipants.URI[idUser]);` – E.Abdel Jun 13 '18 at 10:29
  • Possible duplicate of [Crash or "segmentation fault" when data is copied/scanned/read to an uninitialized pointer](https://stackoverflow.com/questions/37549594/crash-or-segmentation-fault-when-data-is-copied-scanned-read-to-an-uninitializ) – Andrew Henle Jun 13 '18 at 10:29
  • @AndrewHenle I don't think it's the same issue, because then my strlen shold have worked? Please check my edit – rosu alin Jun 13 '18 at 10:42
  • You have to get ride of the '*' when you allocate your pointer, it must be `callerURI= (char *) malloc(sizeof(char *) * (strlen(callerTemp) + 1 ));` – E.Abdel Jun 13 '18 at 10:44
  • But it doesn't even get at the line before that. why does it crash in strlen(callerTemp) – rosu alin Jun 13 '18 at 10:47
  • 1
    Because `strlen` returns a `size_t` not a string, so you have to change the format, try by putting %ld instead of %s in your '13' LOG – E.Abdel Jun 13 '18 at 10:50
  • 1
    yes, yes, just noticed this, sorry. And this is the correct answer. it works now – rosu alin Jun 13 '18 at 10:51

1 Answers1

2
static char* callerURI;

You are not allocating memory here, so callerURI is just a doormat, not a house where you can enter. Before calling strcpy you have to allocate memory for callerURI. Maybe you can use reqParticipants.URI[idUser] to find out the memory you need to allocate.

Gaurav Sehgal
  • 7,422
  • 2
  • 18
  • 34