@@ -24,7 +24,8 @@ struct Activity {
2424 Assets assets;
2525 struct Button {
2626 std::string text = " A button" ;
27- std::string link = " https://github.com/riidefi/RiiStudio/tree/master/source/c-discord-rich-presence" ;
27+ std::string link = " https://github.com/riidefi/RiiStudio/tree/master/"
28+ " source/c-discord-rich-presence" ;
2829 };
2930 std::vector<Button> buttons{Button{}};
3031};
@@ -84,29 +85,39 @@ void rsl_rpc_test(struct C_RPC*);
8485
8586#ifdef __cplusplus
8687namespace discord_rpc {
88+
89+ static inline char * my_strdup (const char * in) {
90+ auto len = strlen (in);
91+ char * buf = (char *)malloc (len + 1 );
92+ memcpy (buf, in, len);
93+ buf[len] = ' \0 ' ;
94+ return buf;
95+ }
96+
8797// Functions to create and destroy the Activity_C struct and to access the
8898// fields of the Activity struct
89- inline Activity_C* create_activity (const Activity& activity) {
99+ static inline Activity_C* create_activity (const Activity& activity) {
90100 Activity_C* activity_c = new Activity_C;
91101
92102 // Allocate and copy strings for state and details
93- activity_c->state = strdup (activity.state .c_str ());
94- activity_c->details = strdup (activity.details .c_str ());
103+ activity_c->state = my_strdup (activity.state .c_str ());
104+ activity_c->details = my_strdup (activity.details .c_str ());
95105
96106 // Copy timestamps and assets
97107 activity_c->timestamps .start = activity.timestamps .start ;
98108 activity_c->timestamps .end = activity.timestamps .end ;
99- activity_c->assets .large_image = strdup (activity.assets .large_image .c_str ());
100- activity_c->assets .large_text = strdup (activity.assets .large_text .c_str ());
109+ activity_c->assets .large_image =
110+ my_strdup (activity.assets .large_image .c_str ());
111+ activity_c->assets .large_text = my_strdup (activity.assets .large_text .c_str ());
101112
102113 // Allocate and copy button vector
103114 activity_c->buttons .length = activity.buttons .size ();
104115 activity_c->buttons .buttons = new Button_C[activity_c->buttons .length ];
105116 for (size_t i = 0 ; i < activity_c->buttons .length ; i++) {
106117 activity_c->buttons .buttons [i].text =
107- strdup (activity.buttons [i].text .c_str ());
118+ my_strdup (activity.buttons [i].text .c_str ());
108119 activity_c->buttons .buttons [i].link =
109- strdup (activity.buttons [i].link .c_str ());
120+ my_strdup (activity.buttons [i].link .c_str ());
110121 }
111122
112123 return activity_c;
0 commit comments