Fix #147510: crash showing integer attribute in spreadsheet on some platforms
The issue here was that I wrongly assumed that the locale would always be available. Instead just use our built-in function to add thousands-separators (which I didn't find last time). Pull Request: https://projects.blender.org/blender/blender/pulls/147515
This commit is contained in:
@@ -21,6 +21,9 @@
|
||||
/* Buffer size of maximum `uint64` plus commas and terminator. */
|
||||
#define BLI_STR_FORMAT_UINT64_GROUPED_SIZE 27
|
||||
|
||||
/* Buffer size of maximum `int64` plus commas and terminator. */
|
||||
#define BLI_STR_FORMAT_INT64_GROUPED_SIZE 28
|
||||
|
||||
/* Buffer size of maximum `int32` with commas and terminator. */
|
||||
#define BLI_STR_FORMAT_INT32_GROUPED_SIZE 15
|
||||
|
||||
@@ -301,6 +304,8 @@ size_t BLI_str_format_int_grouped(char dst[BLI_STR_FORMAT_INT32_GROUPED_SIZE], i
|
||||
*/
|
||||
size_t BLI_str_format_uint64_grouped(char dst[BLI_STR_FORMAT_UINT64_GROUPED_SIZE], uint64_t num)
|
||||
ATTR_NONNULL(1);
|
||||
size_t BLI_str_format_int64_grouped(char dst[BLI_STR_FORMAT_INT64_GROUPED_SIZE], int64_t num)
|
||||
ATTR_NONNULL(1);
|
||||
/**
|
||||
* Format a size in bytes using binary units.
|
||||
* 1000 -> 1 KB
|
||||
|
||||
@@ -1192,6 +1192,18 @@ size_t BLI_str_format_uint64_grouped(char dst[BLI_STR_FORMAT_UINT64_GROUPED_SIZE
|
||||
return BLI_str_format_int_grouped_ex(src, dst, num_len);
|
||||
}
|
||||
|
||||
size_t BLI_str_format_int64_grouped(char dst[BLI_STR_FORMAT_INT64_GROUPED_SIZE], int64_t num)
|
||||
{
|
||||
const size_t dst_maxncpy = BLI_STR_FORMAT_INT64_GROUPED_SIZE;
|
||||
BLI_string_debug_size(dst, dst_maxncpy);
|
||||
UNUSED_VARS_NDEBUG(dst_maxncpy);
|
||||
|
||||
char src[BLI_STR_FORMAT_INT64_GROUPED_SIZE];
|
||||
const int num_len = int(SNPRINTF(src, "%" PRId64 "", num));
|
||||
|
||||
return BLI_str_format_int_grouped_ex(src, dst, num_len);
|
||||
}
|
||||
|
||||
void BLI_str_format_byte_unit(char dst[BLI_STR_FORMAT_INT64_BYTE_UNIT_SIZE],
|
||||
long long int bytes,
|
||||
const bool base_10)
|
||||
|
||||
@@ -390,7 +390,9 @@ class SpreadsheetLayoutDrawer : public SpreadsheetDrawer {
|
||||
break;
|
||||
}
|
||||
default: {
|
||||
value_str = fmt::format(std::locale("en_US.UTF-8"), "{:L}", value);
|
||||
char dst[BLI_STR_FORMAT_INT64_GROUPED_SIZE];
|
||||
BLI_str_format_int64_grouped(dst, value);
|
||||
value_str = dst;
|
||||
break;
|
||||
}
|
||||
}
|
||||
@@ -408,8 +410,9 @@ class SpreadsheetLayoutDrawer : public SpreadsheetDrawer {
|
||||
UI_but_func_tooltip_set(
|
||||
but,
|
||||
[](bContext * /*C*/, void *argN, const StringRef /*tip*/) {
|
||||
return fmt::format(
|
||||
std::locale("en_US.UTF-8"), "{:L} {}", *((int64_t *)argN), TIP_("bytes"));
|
||||
char dst[BLI_STR_FORMAT_INT64_GROUPED_SIZE];
|
||||
BLI_str_format_int64_grouped(dst, *(int64_t *)argN);
|
||||
return fmt::format("{} {}", dst, TIP_("bytes"));
|
||||
},
|
||||
MEM_dupallocN<int64_t>(__func__, value),
|
||||
MEM_freeN);
|
||||
@@ -593,8 +596,9 @@ float ColumnValues::fit_column_values_width_px(const std::optional<int64_t> &max
|
||||
max_sample_size,
|
||||
data_.typed<int64_t>(),
|
||||
[](const int64_t value) {
|
||||
return fmt::format(
|
||||
std::locale("en_US.UTF-8"), "{:L}", value);
|
||||
char dst[BLI_STR_FORMAT_INT64_GROUPED_SIZE];
|
||||
BLI_str_format_int64_grouped(dst, value);
|
||||
return std::string(dst);
|
||||
});
|
||||
}
|
||||
case SPREADSHEET_VALUE_TYPE_FLOAT: {
|
||||
|
||||
Reference in New Issue
Block a user