Skip to content

Remove deprecated score::StringLiteral#745

Open
crimson11 wants to merge 1 commit into
mainfrom
mf_fix_use_string_literal_deprecated
Open

Remove deprecated score::StringLiteral#745
crimson11 wants to merge 1 commit into
mainfrom
mf_fix_use_string_literal_deprecated

Conversation

@crimson11

Copy link
Copy Markdown
Contributor

Removed usage of deprecated
score::StringLiteral in Runtime.
Replaced with const char* and
added verification for NULL-termination.

@limdor limdor left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

const char * has multiple problems and I do not think this should be the substitute for StringLiteral.

  • An std::string can be converted implicitly from const char * ending with dynamic memory allocation
  • const char* has the problem that it could be a pointer to characters or a pointer to an array of bytes. char meaning is way too overloaded in the standard
  • The fact that it is a pointer, it can end up in all the issues with pointer decay
  • It has no notion of being null terminated or not

Because of that, my proposal would be to go for better alternatives.

Additional note: I saw that in several places you removed the usage of StringLiteral, but the dependency to the target and the include is still there. If we remove StringLiteral we should remove it completly and also remove the include files. Of course it can happen that we break some code if someone relies on the transitive dependency but imho this is a price the users need to pay if they did not have proper includes.

Comment thread score/mw/com/runtime_configuration.cpp Outdated
constexpr auto kDeprecatedConfigurationPathCommandLineKey = std::string_view{"-service_instance_manifest"};
constexpr auto kConfigurationPathCommandLineKey = std::string_view{"--service_instance_manifest"};

void VerifyNullTermination(const std::int32_t argc, const char* argv[])

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is something that you cannot do. The problem of this is that if it is null terminated, you will find it, but if it is not null terminated, you hit undefined behavior.
In the second case, it could even be that you hit some null character in memory that it is totally unrelated.

@LittleHuba LittleHuba left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please use C++ infrastructure. E.g. zstring_view or Arguments helper in baselibs.

@crimson11
crimson11 marked this pull request as draft July 23, 2026 06:53
@crimson11

crimson11 commented Jul 23, 2026

Copy link
Copy Markdown
Contributor Author

OK. I guess, I will close this PR then. The thing is: All the usage of const char* stems from the main() entry-point! I.e. there you get const char*, which are guaranteed to be NULL-terminated.
I don't know, how to fix the "issue" then! We expect the user to hand over the char* he gets from the OS in main(). If you now want me to change the signature from our PUBLIC API, where the user currently hands over these char* from main() ... I can't do it.

@limdor , @LittleHuba : Maybe I'm wrong, but to me it seems, that all your input means/can only solved via changng the PUBLIC interface. I.e. require the user NOT to hand over the char* he gets from OS (cmd-line-args) .... if he then also needs to transform these char* to somethings else what is discussed here ... this might also mean eventually heap-allocation ...?

@limdor

limdor commented Jul 23, 2026

Copy link
Copy Markdown
Contributor

Yes, it means breaking public API. But the first step would be to provide a second overload that allows the user to use a container of zstring_view and deprecate the API that uses const char *.
And yes, depending how we do it, it might require allocation at startup for the container, but it can also be an allocation aware type.

@crimson11
crimson11 force-pushed the mf_fix_use_string_literal_deprecated branch from 263c6ca to 9476fed Compare July 24, 2026 14:50
@crimson11
crimson11 marked this pull request as ready for review July 24, 2026 14:51
@crimson11
crimson11 force-pushed the mf_fix_use_string_literal_deprecated branch 2 times, most recently from 88bce04 to 8065b78 Compare July 24, 2026 15:33
Removed usage of deprecated
score::StringLiteral in Runtime.
Replaced with const safecpp::zstring_view
on implementation level. Public/user facing
APIs using StringLiteral or char* have
been marked deprecated and overloads
taking safecpp::zstring_view have been
introduced.
@crimson11
crimson11 force-pushed the mf_fix_use_string_literal_deprecated branch from 8065b78 to ee86368 Compare July 24, 2026 15:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Backlog

Development

Successfully merging this pull request may close these issues.

3 participants