1- /* r2mcp - MIT - Copyright 2025 - pancake, dnakov */
1+ /* r2mcp - MIT - Copyright 2025-2026 - pancake, dnakov */
22
33static void r2state_settings (RCore * core ) {
44 r_config_set_i (core -> config , "scr.color" , 0 );
@@ -46,23 +46,19 @@ static void r2mcp_log_reset(ServerState *ss) {
4646
4747static char * r2mcp_log_drain (ServerState * ss ) {
4848 char * s = r_strbuf_drain (ss -> sb );
49- if (R_STR_ISNOTEMPTY (s )) {
50- ss -> sb = NULL ;
51- return s ;
49+ if (R_STR_ISEMPTY (s )) {
50+ R_FREE (s );
5251 }
53- free (s );
5452 ss -> sb = NULL ;
55- return NULL ;
53+ return s ;
5654}
5755
5856static inline void r2mcp_log (ServerState * ss , const char * x ) {
5957 R_LOG_INFO ("[R2MCP] %s" , x );
60- #if R2MCP_DEBUG
6158 if (ss && ss -> logfile && * ss -> logfile ) {
6259 r_file_dump (ss -> logfile , (const ut8 * ) (x ), -1 , true);
6360 r_file_dump (ss -> logfile , (const ut8 * )"\n" , -1 , true);
6461 }
65- #endif
6662}
6763
6864static char * r2_cmd_filter (const char * cmd , bool * changed ) {
@@ -138,7 +134,7 @@ static bool path_contains_parent_ref(const char *p) {
138134}
139135
140136static bool path_is_within_sandbox (const char * p , const char * sb ) {
141- if (! sb || ! * sb ) {
137+ if (R_STR_ISEMPTY ( sb ) ) {
142138 return true;
143139 }
144140 size_t plen = strlen (p );
@@ -208,7 +204,7 @@ R_IPI bool r2_open_file(ServerState *ss, const char *filepath) {
208204 ss -> rstate .current_file = NULL ;
209205 }
210206
211- bool is_frida = strstr (filepath , "frida://" ) != NULL ;
207+ const bool is_frida = strstr (filepath , "frida://" ) != NULL ;
212208 if (is_frida ) {
213209 ss -> frida_mode = true;
214210 } else {
@@ -222,20 +218,18 @@ R_IPI bool r2_open_file(ServerState *ss, const char *filepath) {
222218 R_LOG_INFO ("Running r2 command: %s" , cmd );
223219 char * result = r_core_cmd_str (core , cmd );
224220 free (cmd );
225- bool success = ( result && strlen (result ) > 0 );
221+ bool success = R_STR_ISNOTEMPTY (result );
226222 free (result );
227223
228224 if (!success ) {
229225 R_LOG_INFO ("Trying alternative method to open file" );
230226 RIODesc * fd = r_core_file_open (core , filepath , R_PERM_R , 0 );
231- if (fd ) {
232- r_core_bin_load (core , filepath , 0 );
233- R_LOG_INFO ("File opened using r_core_file_open" );
234- success = true;
235- } else {
227+ if (!fd ) {
236228 R_LOG_ERROR ("Failed to open file: %s" , filepath );
237229 return false;
238230 }
231+ r_core_bin_load (core , filepath , 0 );
232+ R_LOG_INFO ("File opened using r_core_file_open" );
239233 }
240234 free (ss -> rstate .current_file );
241235 ss -> rstate .current_file = strdup (filepath );
0 commit comments