Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

StringUtils: remove legacy fmt::sprintf usage #19796

Merged
merged 2 commits into from
May 28, 2021

Conversation

lrusak
Copy link
Contributor

@lrusak lrusak commented May 24, 2021

This cleans ups the StringUtils::Format method now that all the format strings are updated to the new style.

Removing the sprintf method makes it so that old sprintf formatting won't work anymore! Be aware!

@lrusak lrusak added Type: Cleanup non-breaking change which removes non-working or unmaintained functionality v20 Nexus labels May 24, 2021
@lrusak lrusak added this to the N* 20.0 Alpha 1 milestone May 24, 2021
@lrusak lrusak requested review from Montellese and garbear May 24, 2021 23:47
Copy link
Member

@Montellese Montellese left a comment

Choose a reason for hiding this comment

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

Do you plan on replacing all calls to StringUtils::Format() with direct calls to fmt::format()? IMO that would make it more clear that you can't use sprintf() style syntax anymore and you would also benefit from other libfmt features like named arguments etc.

Obviously we would need a temporary workaround for those cases where the EnumToInt() hack applies.

@lrusak
Copy link
Contributor Author

lrusak commented May 25, 2021

Do you plan on replacing all calls to StringUtils::Format() with direct calls to fmt::format()? IMO that would make it more clear that you can't use sprintf() style syntax anymore and you would also benefit from other libfmt features like named arguments etc.

I've thought about this, I'm not sure yet though if we should just add a try/catch block here to catch any invalid formatting or not.

Obviously we would need a temporary workaround for those cases where the EnumToInt() hack applies.

I'll take a look to see when libfmt started supporting enums and see if we can bump/drop the workaround.

@lrusak
Copy link
Contributor Author

lrusak commented May 25, 2021

I'm not really sure why the tests are failing here. I quick look over doesn't reveal anything obvious.

@Montellese
Copy link
Member

@lrusak: The problem is located here: https://github.com/xbmc/xbmc/blob/master/xbmc/utils/HttpRangeUtils.cpp#L25. Your regex missed this formatting pattern (because it's not very obvious). Changing that line to use "{}" instead of "%" PRIu64 fixes all failing unit tests on Win64 for me.

I also found https://github.com/xbmc/xbmc/blob/master/xbmc/events/BaseEvent.cpp#L106 by grepping for PRI[a-z]*[0-9]+

@lrusak lrusak force-pushed the format-update-next-sprintf branch from 055bea3 to 6d31448 Compare May 25, 2021 21:00
@lrusak
Copy link
Contributor Author

lrusak commented May 25, 2021

@Montellese thanks for the hints!

@lrusak
Copy link
Contributor Author

lrusak commented May 27, 2021

Should we merge this as is? I think the next step would be to remove StringUtils::Format completely.

@Montellese
Copy link
Member

For me this is good to go.

@lrusak lrusak merged commit c3cc394 into xbmc:master May 28, 2021
@howie-f
Copy link
Contributor

howie-f commented May 29, 2021

next step would be to remove StringUtils::Format completely

how would we catch exceptions caused by malformed strings of any kind when Format is removed?

@ronie
Copy link
Member

ronie commented May 29, 2021

@lrusak this is causing some issues, most notably the 'recently added movies' / 'recently added episodes' disappeared from Estuary's home screen.

before this PR
before

with this PR
after

Also the file naming of screenshots is broken..

before:
screenshot0000.png

after:
screenshot%05d.png

@fuzzard
Copy link
Contributor

fuzzard commented May 29, 2021

std::string CUtil::GetNextFilename(const std::string &fn_template, int max)

Would be where the screenshot stuff is going wrong. Filecache stuff looks like it'll be affected as well

@ronie
Copy link
Member

ronie commented May 29, 2021

related errors from the log

2021-05-30 01:24:12.448 T:253782 ERROR : SQL: [MyVideos119.db] SQLite error SQLITE_ERROR (near "%": syntax error)
Query: select * from movie_view WHERE ((%s > '2012-01-01')) AND ((movie_view.playCount IS NULL OR movie_view.playCount < 1))

2021-05-30 01:24:12.464 T:253781 ERROR : SQL: [MyVideos119.db] SQLite error SQLITE_ERROR (near "%": syntax error)
Query: select * from episode_view WHERE ((%s > '2012-01-01')) AND ((episode_view.playCount IS NULL OR episode_view.playCount < 1))

@Montellese
Copy link
Member

related errors from the log

2021-05-30 01:24:12.448 T:253782 ERROR : SQL: [MyVideos119.db] SQLite error SQLITE_ERROR (near "%": syntax error)
Query: select * from movie_view WHERE ((%s > '2012-01-01')) AND ((movie_view.playCount IS NULL OR movie_view.playCount < 1))

2021-05-30 01:24:12.464 T:253781 ERROR : SQL: [MyVideos119.db] SQLite error SQLITE_ERROR (near "%": syntax error)
Query: select * from episode_view WHERE ((%s > '2012-01-01')) AND ((episode_view.playCount IS NULL OR episode_view.playCount < 1))

Beware that all SQL queries must use PrepareSQL() and not StringUtils::Format(). While it works as well it foregoes some SQL specific checks (like SQL injections) and workarounds to support both SQLite and MySQL.

@DaveTBlake
Copy link
Member

Needless to say that the music smart playlists are also broken by this change too.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Type: Cleanup non-breaking change which removes non-working or unmaintained functionality v20 Nexus
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

7 participants