Skip to content

Commit 78fa543

Browse files
committed
SmallString: Make constructors explicit
Catch more errors at compile-time.
1 parent d9dc507 commit 78fa543

File tree

5 files changed

+23
-10
lines changed

5 files changed

+23
-10
lines changed

src/common/small_string.h

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -266,13 +266,13 @@ class SmallStackString : public SmallStringBase
266266
public:
267267
ALWAYS_INLINE SmallStackString() { init(); }
268268

269-
ALWAYS_INLINE SmallStackString(const char* str)
269+
ALWAYS_INLINE explicit SmallStackString(const char* str)
270270
{
271271
init();
272272
assign(str);
273273
}
274274

275-
ALWAYS_INLINE SmallStackString(const char* str, u32 length)
275+
ALWAYS_INLINE explicit SmallStackString(const char* str, u32 length)
276276
{
277277
init();
278278
assign(str, length);
@@ -290,19 +290,25 @@ class SmallStackString : public SmallStringBase
290290
assign(move);
291291
}
292292

293-
ALWAYS_INLINE SmallStackString(const SmallStackString& copy)
293+
ALWAYS_INLINE explicit SmallStackString(const SmallStackString& copy)
294294
{
295295
init();
296296
assign(copy);
297297
}
298298

299-
ALWAYS_INLINE SmallStackString(SmallStackString&& move)
299+
ALWAYS_INLINE explicit SmallStackString(SmallStackString&& move)
300300
{
301301
init();
302302
assign(move);
303303
}
304304

305-
ALWAYS_INLINE SmallStackString(const std::string_view sv)
305+
ALWAYS_INLINE explicit SmallStackString(const std::string& str)
306+
{
307+
init();
308+
assign(str);
309+
}
310+
311+
ALWAYS_INLINE explicit SmallStackString(const std::string_view sv)
306312
{
307313
init();
308314
assign(sv);
@@ -332,6 +338,12 @@ class SmallStackString : public SmallStringBase
332338
return *this;
333339
}
334340

341+
ALWAYS_INLINE SmallStackString& operator=(const std::string& str)
342+
{
343+
assign(str);
344+
return *this;
345+
}
346+
335347
ALWAYS_INLINE SmallStackString& operator=(const std::string_view sv)
336348
{
337349
assign(sv);

src/core/achievements.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3815,7 +3815,7 @@ static TinyString GetLoginEncryptionMachineKey()
38153815
{
38163816
WARNING_LOG("Get MachineGuid failed: {}", error);
38173817
RegCloseKey(hKey);
3818-
return 0;
3818+
return ret;
38193819
}
38203820

38213821
ret.resize(machine_guid_length);
@@ -3826,7 +3826,7 @@ static TinyString GetLoginEncryptionMachineKey()
38263826
WARNING_LOG("Read MachineGuid failed: {}", error);
38273827
ret = {};
38283828
RegCloseKey(hKey);
3829-
return 0;
3829+
return ret;
38303830
}
38313831

38323832
ret.resize(machine_guid_length);

src/core/system.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6192,7 +6192,7 @@ void System::UpdateRichPresence(bool update_session_time)
61926192
rp.largeImageText = "DuckStation PS1/PSX Emulator";
61936193
rp.startTimestamp = s_state.discord_presence_time_epoch;
61946194

6195-
TinyString game_details = "No Game Running";
6195+
TinyString game_details("No Game Running");
61966196
if (IsValidOrInitializing())
61976197
{
61986198
// Use disc set name if it's not a custom title.

src/util/cubeb_audio_stream.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,8 @@ static TinyString GetCubebErrorString(int rv)
5959
C(CUBEB_ERROR_DEVICE_UNAVAILABLE);
6060

6161
default:
62-
return "CUBEB_ERROR_UNKNOWN";
62+
ret = "CUBEB_ERROR_UNKNOWN";
63+
break;
6364

6465
#undef C
6566
}

src/util/vulkan_swap_chain.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -249,7 +249,7 @@ std::optional<VkSurfaceFormatKHR> VulkanSwapChain::SelectSurfaceFormat(VkPhysica
249249
return VkSurfaceFormatKHR{format, VK_COLOR_SPACE_SRGB_NONLINEAR_KHR};
250250
}
251251

252-
SmallString errormsg = "Failed to find a suitable format for swap chain buffers. Available formats were:";
252+
SmallString errormsg("Failed to find a suitable format for swap chain buffers. Available formats were:");
253253
for (const VkSurfaceFormatKHR& sf : surface_formats)
254254
errormsg.append_format(" {}", static_cast<unsigned>(sf.format));
255255
Error::SetStringView(error, errormsg);

0 commit comments

Comments
 (0)