Skip to content

Commit

Permalink
std::format doesn't like null pointers when printing strings
Browse files Browse the repository at this point in the history
  • Loading branch information
grendello committed Nov 29, 2024
1 parent 45e68c3 commit 0e11dc4
Show file tree
Hide file tree
Showing 14 changed files with 293 additions and 183 deletions.
22 changes: 11 additions & 11 deletions src/native/monodroid/debug.cc
Original file line number Diff line number Diff line change
Expand Up @@ -96,8 +96,8 @@ Debug::monodroid_profiler_load (const char *libmono_path, const char *desc, cons
if (!found)
log_warn (LOG_DEFAULT,
"The '{}' profiler wasn't found in the main executable nor could it be loaded from '{}'.",
mname.get (),
libname.get ()
optional_string (mname.get ()),
optional_string (libname.get ())
);
}

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

if (func != nullptr) {
func (desc);
Expand Down Expand Up @@ -139,7 +139,7 @@ Debug::parse_options (char *options, ConnOptions *opts)
{
char **args, **ptr;

log_info (LOG_DEFAULT, "Connection options: '{}'", options);
log_info (LOG_DEFAULT, "Connection options: '{}'", optional_string (options));

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

Expand All @@ -163,7 +163,7 @@ Debug::parse_options (char *options, ConnOptions *opts)
if ((endp == arg) || (*endp != '\0'))
log_error (LOG_DEFAULT, "Invalid --timeout argument."sv);
} else {
log_info (LOG_DEFAULT, "Unknown connection option: '{}'", arg);
log_info (LOG_DEFAULT, "Unknown connection option: '{}'", optional_string (arg));
}
}
}
Expand Down Expand Up @@ -275,7 +275,7 @@ Debug::process_connection (int fd)
// null-terminate
command [cmd_len] = 0;

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

if (process_cmd (fd, command))
return true;
Expand Down Expand Up @@ -487,7 +487,7 @@ Debug::process_cmd (int fd, char *cmd)
profiler_fd = fd;
profiler_description = Util::monodroid_strdup_printf ("%s,output=#%i", prof, profiler_fd);
} else {
log_error (LOG_DEFAULT, "Unknown profiler: '{}'", prof);
log_error (LOG_DEFAULT, "Unknown profiler: '{}'", optional_string (prof));
}
/* Notify the main thread (start_profiling ()) */
profiler_configured = true;
Expand All @@ -496,7 +496,7 @@ Debug::process_cmd (int fd, char *cmd)
pthread_mutex_unlock (&process_cmd_mutex);
return use_fd;
} else {
log_error (LOG_DEFAULT, "Unsupported command: '{}'", cmd);
log_error (LOG_DEFAULT, "Unsupported command: '{}'", optional_string (cmd));
}

return false;
Expand Down Expand Up @@ -526,7 +526,7 @@ Debug::start_debugging (void)

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

if (enable_soft_breakpoints ()) {
constexpr std::string_view soft_breakpoints { "--soft-breakpoints" };
Expand Down Expand Up @@ -588,10 +588,10 @@ Debug::enable_soft_breakpoints (void)
bool ret;
if (strcmp ("0", value) == 0) {
ret = false;
log_info (LOG_DEBUGGER, "soft breakpoints disabled ({} property set to {})", SharedConstants::DEBUG_MONO_SOFT_BREAKPOINTS.data (), value);
log_info (LOG_DEBUGGER, "soft breakpoints disabled ({} property set to {})", SharedConstants::DEBUG_MONO_SOFT_BREAKPOINTS.data (), optional_string (value));
} else {
ret = true;
log_info (LOG_DEBUGGER, "soft breakpoints enabled ({} property set to {})", SharedConstants::DEBUG_MONO_SOFT_BREAKPOINTS.data (), value);
log_info (LOG_DEBUGGER, "soft breakpoints enabled ({} property set to {})", SharedConstants::DEBUG_MONO_SOFT_BREAKPOINTS.data (), optional_string (value));
}
delete[] value;
return ret;
Expand Down
33 changes: 20 additions & 13 deletions src/native/monodroid/embedded-assemblies-zip.cc
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,14 @@ EmbeddedAssemblies::zip_load_entry_common (size_t entry_index, std::vector<uint8

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

log_debug (LOG_ASSEMBLY, "{} entry: {}", state.file_name, entry_name.get () == nullptr ? "unknown"sv : entry_name.get ());
log_debug (LOG_ASSEMBLY, "{} entry: {}", optional_string (state.file_name), optional_string (entry_name.get (), "unknown"));
if (!result || entry_name.empty ()) {
Helpers::abort_application (
LOG_ASSEMBLY,
std::format (
"Failed to read Central Directory info for entry {} in APK {}",
entry_index,
state.file_name
optional_string (state.file_name)
)
);
}
Expand All @@ -40,7 +40,7 @@ EmbeddedAssemblies::zip_load_entry_common (size_t entry_index, std::vector<uint8
std::format (
"Failed to adjust data start offset for entry {} in APK {}",
entry_index,
state.file_name
optional_string (state.file_name)
)
);
}
Expand Down Expand Up @@ -76,7 +76,7 @@ EmbeddedAssemblies::zip_load_entry_common (size_t entry_index, std::vector<uint8
LOG_ASSEMBLY,
std::format (
"Assembly '{}' is at bad offset {} in the APK (not aligned to 4 or 16 bytes). 'zipalign' MUST be used on {} to align it properly",
entry_name.get (),
optional_string (entry_name.get ()),
state.data_offset,
strrchr (state.file_name, '/') + 1
)
Expand Down Expand Up @@ -139,7 +139,12 @@ EmbeddedAssemblies::store_individual_assembly_data (dynamic_local_string<SENSIBL

log_debug (LOG_ASSEMBLY, "Setting bundled assembly entry data at index {}", bundled_assembly_index);
set_assembly_entry_data (bundled_assemblies [bundled_assembly_index], state, entry_name);
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);
log_debug (LOG_ASSEMBLY,
"[{}] data set: name == '{}'; file_name == '{}'",
bundled_assembly_index,
optional_string (bundled_assemblies [bundled_assembly_index].name),
optional_string (bundled_assemblies [bundled_assembly_index].file_name)
);
bundled_assembly_index++;
number_of_found_assemblies = bundled_assembly_index;
have_and_want_debug_symbols = register_debug_symbols && bundled_debug_data != nullptr;
Expand Down Expand Up @@ -222,7 +227,7 @@ EmbeddedAssemblies::map_assembly_store (dynamic_local_string<SENSIBLE_PATH_MAX>
LOG_ASSEMBLY,
std::format (
"Assembly store '{}' is not a valid .NET for Android assembly store file",
entry_name.get ()
optional_string (entry_name.get ())
)
);
}
Expand All @@ -232,7 +237,7 @@ EmbeddedAssemblies::map_assembly_store (dynamic_local_string<SENSIBLE_PATH_MAX>
LOG_ASSEMBLY,
std::format (
"Assembly store '{}' uses format version {:x}, instead of the expected {:x}",
entry_name.get (),
optional_string (entry_name.get ()),
header->version,
ASSEMBLY_STORE_FORMAT_VERSION
)
Expand Down Expand Up @@ -299,9 +304,9 @@ EmbeddedAssemblies::zip_load_assembly_store_entries (std::vector<uint8_t> const&
log_debug (
LOG_ASSEMBLY,
"Found a shared library entry {} (index: {}; name: {}; hash: {:x}; apk offset: {})",
entry_name.get (),
optional_string (entry_name.get ()),
number_of_zip_dso_entries,
name,
optional_string (name),
apk_entry->name_hash,
apk_entry->offset
);
Expand All @@ -322,7 +327,7 @@ EmbeddedAssemblies::zip_load_entries (int fd, const char *apk_name, [[maybe_unus
LOG_ASSEMBLY,
std::format (
"Failed to read the EOCD record from APK file %s",
apk_name
optional_string (apk_name)
)
);
}
Expand All @@ -340,7 +345,7 @@ EmbeddedAssemblies::zip_load_entries (int fd, const char *apk_name, [[maybe_unus
std::strerror (errno),
retval,
errno,
apk_name
optional_string (apk_name)
)
);
}
Expand Down Expand Up @@ -371,7 +376,7 @@ EmbeddedAssemblies::zip_load_entries (int fd, const char *apk_name, [[maybe_unus
std::strerror (errno),
nread,
errno,
apk_name
optional_string (apk_name)
)
);
}
Expand Down Expand Up @@ -408,7 +413,9 @@ EmbeddedAssemblies::set_entry_data (XamarinAndroidBundledAssembly &entry, ZipEnt
log_debug (
LOG_ASSEMBLY,
"Set bundled assembly entry data. file name: '{}'; entry name: '{}'; data size: {}",
entry.file_name, entry.name, entry.data_size
optional_string (entry.file_name),
optional_string (entry.name),
entry.data_size
);
}

Expand Down
Loading

0 comments on commit 0e11dc4

Please sign in to comment.