Skip to content

Commit 0e11dc4

Browse files
committed
std::format doesn't like null pointers when printing strings
1 parent 45e68c3 commit 0e11dc4

14 files changed

+293
-183
lines changed

src/native/monodroid/debug.cc

+11-11
Original file line numberDiff line numberDiff line change
@@ -96,8 +96,8 @@ Debug::monodroid_profiler_load (const char *libmono_path, const char *desc, cons
9696
if (!found)
9797
log_warn (LOG_DEFAULT,
9898
"The '{}' profiler wasn't found in the main executable nor could it be loaded from '{}'.",
99-
mname.get (),
100-
libname.get ()
99+
optional_string (mname.get ()),
100+
optional_string (libname.get ())
101101
);
102102
}
103103

@@ -109,7 +109,7 @@ bool
109109
Debug::load_profiler (void *handle, const char *desc, const char *symbol)
110110
{
111111
ProfilerInitializer func = reinterpret_cast<ProfilerInitializer> (java_interop_lib_symbol (handle, symbol, nullptr));
112-
log_warn (LOG_DEFAULT, "Looking for profiler init symbol '{}'? {:p}", symbol, reinterpret_cast<void*>(func));
112+
log_warn (LOG_DEFAULT, "Looking for profiler init symbol '{}'? {:p}", optional_string (symbol), reinterpret_cast<void*>(func));
113113

114114
if (func != nullptr) {
115115
func (desc);
@@ -139,7 +139,7 @@ Debug::parse_options (char *options, ConnOptions *opts)
139139
{
140140
char **args, **ptr;
141141

142-
log_info (LOG_DEFAULT, "Connection options: '{}'", options);
142+
log_info (LOG_DEFAULT, "Connection options: '{}'", optional_string (options));
143143

144144
args = Util::monodroid_strsplit (options, ",", 0);
145145

@@ -163,7 +163,7 @@ Debug::parse_options (char *options, ConnOptions *opts)
163163
if ((endp == arg) || (*endp != '\0'))
164164
log_error (LOG_DEFAULT, "Invalid --timeout argument."sv);
165165
} else {
166-
log_info (LOG_DEFAULT, "Unknown connection option: '{}'", arg);
166+
log_info (LOG_DEFAULT, "Unknown connection option: '{}'", optional_string (arg));
167167
}
168168
}
169169
}
@@ -275,7 +275,7 @@ Debug::process_connection (int fd)
275275
// null-terminate
276276
command [cmd_len] = 0;
277277

278-
log_info (LOG_DEFAULT, "Received cmd: '{}'.", command);
278+
log_info (LOG_DEFAULT, "Received cmd: '{}'.", optional_string (command));
279279

280280
if (process_cmd (fd, command))
281281
return true;
@@ -487,7 +487,7 @@ Debug::process_cmd (int fd, char *cmd)
487487
profiler_fd = fd;
488488
profiler_description = Util::monodroid_strdup_printf ("%s,output=#%i", prof, profiler_fd);
489489
} else {
490-
log_error (LOG_DEFAULT, "Unknown profiler: '{}'", prof);
490+
log_error (LOG_DEFAULT, "Unknown profiler: '{}'", optional_string (prof));
491491
}
492492
/* Notify the main thread (start_profiling ()) */
493493
profiler_configured = true;
@@ -496,7 +496,7 @@ Debug::process_cmd (int fd, char *cmd)
496496
pthread_mutex_unlock (&process_cmd_mutex);
497497
return use_fd;
498498
} else {
499-
log_error (LOG_DEFAULT, "Unsupported command: '{}'", cmd);
499+
log_error (LOG_DEFAULT, "Unsupported command: '{}'", optional_string (cmd));
500500
}
501501

502502
return false;
@@ -526,7 +526,7 @@ Debug::start_debugging (void)
526526

527527
// this text is used in unit tests to check the debugger started
528528
// do not change it without updating the test.
529-
log_warn (LOG_DEBUGGER, "Trying to initialize the debugger with options: {}", debug_arg);
529+
log_warn (LOG_DEBUGGER, "Trying to initialize the debugger with options: {}", optional_string (debug_arg));
530530

531531
if (enable_soft_breakpoints ()) {
532532
constexpr std::string_view soft_breakpoints { "--soft-breakpoints" };
@@ -588,10 +588,10 @@ Debug::enable_soft_breakpoints (void)
588588
bool ret;
589589
if (strcmp ("0", value) == 0) {
590590
ret = false;
591-
log_info (LOG_DEBUGGER, "soft breakpoints disabled ({} property set to {})", SharedConstants::DEBUG_MONO_SOFT_BREAKPOINTS.data (), value);
591+
log_info (LOG_DEBUGGER, "soft breakpoints disabled ({} property set to {})", SharedConstants::DEBUG_MONO_SOFT_BREAKPOINTS.data (), optional_string (value));
592592
} else {
593593
ret = true;
594-
log_info (LOG_DEBUGGER, "soft breakpoints enabled ({} property set to {})", SharedConstants::DEBUG_MONO_SOFT_BREAKPOINTS.data (), value);
594+
log_info (LOG_DEBUGGER, "soft breakpoints enabled ({} property set to {})", SharedConstants::DEBUG_MONO_SOFT_BREAKPOINTS.data (), optional_string (value));
595595
}
596596
delete[] value;
597597
return ret;

src/native/monodroid/embedded-assemblies-zip.cc

+20-13
Original file line numberDiff line numberDiff line change
@@ -22,14 +22,14 @@ EmbeddedAssemblies::zip_load_entry_common (size_t entry_index, std::vector<uint8
2222

2323
bool result = zip_read_entry_info (buf, entry_name, state);
2424

25-
log_debug (LOG_ASSEMBLY, "{} entry: {}", state.file_name, entry_name.get () == nullptr ? "unknown"sv : entry_name.get ());
25+
log_debug (LOG_ASSEMBLY, "{} entry: {}", optional_string (state.file_name), optional_string (entry_name.get (), "unknown"));
2626
if (!result || entry_name.empty ()) {
2727
Helpers::abort_application (
2828
LOG_ASSEMBLY,
2929
std::format (
3030
"Failed to read Central Directory info for entry {} in APK {}",
3131
entry_index,
32-
state.file_name
32+
optional_string (state.file_name)
3333
)
3434
);
3535
}
@@ -40,7 +40,7 @@ EmbeddedAssemblies::zip_load_entry_common (size_t entry_index, std::vector<uint8
4040
std::format (
4141
"Failed to adjust data start offset for entry {} in APK {}",
4242
entry_index,
43-
state.file_name
43+
optional_string (state.file_name)
4444
)
4545
);
4646
}
@@ -76,7 +76,7 @@ EmbeddedAssemblies::zip_load_entry_common (size_t entry_index, std::vector<uint8
7676
LOG_ASSEMBLY,
7777
std::format (
7878
"Assembly '{}' is at bad offset {} in the APK (not aligned to 4 or 16 bytes). 'zipalign' MUST be used on {} to align it properly",
79-
entry_name.get (),
79+
optional_string (entry_name.get ()),
8080
state.data_offset,
8181
strrchr (state.file_name, '/') + 1
8282
)
@@ -139,7 +139,12 @@ EmbeddedAssemblies::store_individual_assembly_data (dynamic_local_string<SENSIBL
139139

140140
log_debug (LOG_ASSEMBLY, "Setting bundled assembly entry data at index {}", bundled_assembly_index);
141141
set_assembly_entry_data (bundled_assemblies [bundled_assembly_index], state, entry_name);
142-
log_debug (LOG_ASSEMBLY, "[{}] data set: name == '{}'; file_name == '{}'", bundled_assembly_index, bundled_assemblies [bundled_assembly_index].name, bundled_assemblies [bundled_assembly_index].file_name);
142+
log_debug (LOG_ASSEMBLY,
143+
"[{}] data set: name == '{}'; file_name == '{}'",
144+
bundled_assembly_index,
145+
optional_string (bundled_assemblies [bundled_assembly_index].name),
146+
optional_string (bundled_assemblies [bundled_assembly_index].file_name)
147+
);
143148
bundled_assembly_index++;
144149
number_of_found_assemblies = bundled_assembly_index;
145150
have_and_want_debug_symbols = register_debug_symbols && bundled_debug_data != nullptr;
@@ -222,7 +227,7 @@ EmbeddedAssemblies::map_assembly_store (dynamic_local_string<SENSIBLE_PATH_MAX>
222227
LOG_ASSEMBLY,
223228
std::format (
224229
"Assembly store '{}' is not a valid .NET for Android assembly store file",
225-
entry_name.get ()
230+
optional_string (entry_name.get ())
226231
)
227232
);
228233
}
@@ -232,7 +237,7 @@ EmbeddedAssemblies::map_assembly_store (dynamic_local_string<SENSIBLE_PATH_MAX>
232237
LOG_ASSEMBLY,
233238
std::format (
234239
"Assembly store '{}' uses format version {:x}, instead of the expected {:x}",
235-
entry_name.get (),
240+
optional_string (entry_name.get ()),
236241
header->version,
237242
ASSEMBLY_STORE_FORMAT_VERSION
238243
)
@@ -299,9 +304,9 @@ EmbeddedAssemblies::zip_load_assembly_store_entries (std::vector<uint8_t> const&
299304
log_debug (
300305
LOG_ASSEMBLY,
301306
"Found a shared library entry {} (index: {}; name: {}; hash: {:x}; apk offset: {})",
302-
entry_name.get (),
307+
optional_string (entry_name.get ()),
303308
number_of_zip_dso_entries,
304-
name,
309+
optional_string (name),
305310
apk_entry->name_hash,
306311
apk_entry->offset
307312
);
@@ -322,7 +327,7 @@ EmbeddedAssemblies::zip_load_entries (int fd, const char *apk_name, [[maybe_unus
322327
LOG_ASSEMBLY,
323328
std::format (
324329
"Failed to read the EOCD record from APK file %s",
325-
apk_name
330+
optional_string (apk_name)
326331
)
327332
);
328333
}
@@ -340,7 +345,7 @@ EmbeddedAssemblies::zip_load_entries (int fd, const char *apk_name, [[maybe_unus
340345
std::strerror (errno),
341346
retval,
342347
errno,
343-
apk_name
348+
optional_string (apk_name)
344349
)
345350
);
346351
}
@@ -371,7 +376,7 @@ EmbeddedAssemblies::zip_load_entries (int fd, const char *apk_name, [[maybe_unus
371376
std::strerror (errno),
372377
nread,
373378
errno,
374-
apk_name
379+
optional_string (apk_name)
375380
)
376381
);
377382
}
@@ -408,7 +413,9 @@ EmbeddedAssemblies::set_entry_data (XamarinAndroidBundledAssembly &entry, ZipEnt
408413
log_debug (
409414
LOG_ASSEMBLY,
410415
"Set bundled assembly entry data. file name: '{}'; entry name: '{}'; data size: {}",
411-
entry.file_name, entry.name, entry.data_size
416+
optional_string (entry.file_name),
417+
optional_string (entry.name),
418+
entry.data_size
412419
);
413420
}
414421

0 commit comments

Comments
 (0)