Commit Graph

37 Commits

Author SHA1 Message Date
Peter Nelson a28ab8cac2
Codechange: Replace C-style casts to size_t with static_cast. (#12455)
* Codechange: Replace C-style casts to size_t with static_cast.

This touches only simple value-type casts.

* Codechange: Replace static_cast<size_t>(-1) with SIZE_MAX

Co-authored-by: Rubidium <rubidium@openttd.org>
2024-04-19 20:34:36 +01:00
Peter Nelson 6ee31a2a22
Codechange: Use string_view in IniItem/IniGroup/IniFile. (#12535)
This avoids making extra copies of strings.
2024-04-19 13:54:22 +01:00
Jonathan G Rennison 88324a253e
Fix #11644: Off by one error/buffer over-read in StrMakeValid (#11645)
* Fix #11644: Off by one error in StrMakeValid UTF-8 decode overrun detection

* Fix #11644: Off by one error in StrMakeValid buffer last character

* Fix: Unnecessary string duplication at StrMakeValid call sites
2024-01-01 13:26:31 -05:00
Peter Nelson 35a7770fde
Fix 233aac5: Set newline default comment for new groups. (#11411)
The newline space between ini groups is actually recorded as a comment of the group. This got inadvertantly dropped in #11364.
2023-10-31 01:19:04 +00:00
Peter Nelson 69e20e79ab Codechange: Add const versions of GetItem/GetGroup, and sprinkle liberally.
Non-const version of GetItem is not needed.
2023-10-20 18:37:27 +01:00
Peter Nelson 233aac567b Codechange: Use std::list instead of C-linked list for ini files.
This removes self-management of memory with new/delete and allows simpler iteration.
2023-10-20 18:37:27 +01:00
Peter Nelson ec1cf96b62 Codechange: Move initialization of group-type to CreateGroup function. 2023-10-20 18:37:27 +01:00
Peter Nelson 8bd06807e4 Codechange: Pass initializer list instead of null-terminated list of group types. 2023-10-20 18:37:27 +01:00
Peter Nelson 1fecbeff76 Codechange: Remove create parameter from IniLoadFile::GetGroup.
GetGroup now only returns nullptr if the group does not exist.
Use GetOrCreateGroup to create a group.

This avoids creating groups while reading ini files.
2023-10-20 18:37:27 +01:00
Peter Nelson 6ce7195ef1 Codechange: Split GetGroup into GetGroup/GetOrCreateGroup.
This follows the pattern used for GetItem/GetOrCreateItem, and allows use
of references where we know the group must exist.
2023-10-20 18:37:27 +01:00
Peter Nelson d3c5ae2648 Codechange: Add CreateGroup/CreateItem methods for ini files.
This abstracts the internals a bit.
2023-10-20 18:37:27 +01:00
Peter Nelson 3961318974 Codechange: Accept std::string in RemoveGroup(). 2023-10-20 18:37:27 +01:00
PeterN 9fa1984ef0
Codechange: IniGroup::GetItem() can now be const. (#10966) 2023-06-06 22:39:37 +00:00
PeterN 64d6ad50f9
Codechange: Split GetItem with GetOrCreateItem. (#10952)
`IniGroup::GetItem()` returns nullptr if the item does not exist, but does not if the create parameter is set to true. Resolve CodeQL warnings with `GetOrCreateItem()` which returns a reference to the item instead.
2023-06-05 18:29:52 +00:00
Patric Stout ab601115a9
Fix 75b6051b: removing items from the ini could leave the group in a bad state (#9445) 2021-07-17 17:26:50 +02:00
Patric Stout 75b6051b7a Change: move sensitive information to secrets.cfg and private information to private.cfg
We often ask people for their openttd.cfg, which now includes their
passwords, usernames, etc. It is easy for people to overlook this,
unwillingly sharing information they shouldn't.

By splitting this information over either private.cfg or secrets.cfg,
we make it more obvious they shouldn't be sharing those files, and
hint to what is inside them.
2021-07-02 14:30:14 +02:00
Patric Stout ca9a7df752
Codechange: rename str_validate to StrMakeValid(InPlace) (#9304)
This to be more explicit the function changes the value, and not
returns yes/no.
2021-05-29 11:21:38 +02:00
rubidium42 a032714dc4 Codechange: move script settings to std::string 2021-05-13 23:13:17 +02:00
Charles Pigott 9b800a96ed
Codechange: Remove min/max functions in favour of STL variants (#8502) 2021-01-08 11:16:18 +01:00
Michael Lutz 358056ec42 Codechange: Keep filenames of loaded Fio files in std::strings. 2020-12-27 13:19:25 +01:00
Michael Lutz dd138fc460 Codechange: Stringify config file paths. 2020-12-27 13:19:25 +01:00
Michael Lutz 715aa67a9c Codechange: Use std::string in INI file parsing. 2020-05-21 20:02:34 +02:00
S. D. Cloudt 13cc8a0cee Cleanup: Removed SVN headers 2019-11-10 17:59:20 +00:00
Henry Wilson 7c8e7c6b6e Codechange: Use null pointer literal instead of the NULL macro 2019-04-10 23:22:20 +02:00
rubidium 9ed12b0f07 (svn r26509) -Codechange: replace strdup with stredup (the latter ensures the return is not NULL) 2014-04-25 15:40:32 +00:00
frosch d71cc434e4 (svn r26504) -Fix (r26499): Obiwan and his gang. 2014-04-24 18:58:47 +00:00
rubidium 8960939b22 (svn r26499) -Codechange: replace strndup with stredup 2014-04-24 18:37:39 +00:00
rubidium 0463dbdc9e (svn r26482) -Codechange: add an include that allows us to undefine/redefine "unsafe" functions to prevent them from being used, and thus having to care about certain aspects of their return values 2014-04-23 20:13:33 +00:00
rubidium 4b355534c0 (svn r26476) -Fix: prevent comparing to NULL when strndup could not allocate memory 2014-04-20 16:43:22 +00:00
frosch 7247ecf172 (svn r26206) -Fix [FS#5829]: Run everything from ini, obg, obs, obs, ... files through str_validate. 2014-01-02 17:55:57 +00:00
rubidium d8d2f74559 (svn r23741) -Revert (r23740): the few parts that the Windows / non-network compiles stumble on 2012-01-03 21:47:01 +00:00
rubidium 6d6be50ae0 (svn r23740) -Codechange: remove some 300 unneeded includes from the .cpp files 2012-01-03 21:32:51 +00:00
rubidium 05300a00b1 (svn r22824) -Codechange: pass sub directory to ini loading 2011-08-24 13:38:26 +00:00
alberth fa9c193539 (svn r22170) -Add: Add IGT_SEQUENCE type for loading ini group lines without further interpretation. 2011-03-03 20:56:33 +00:00
alberth 6a88af662b (svn r22169) -Add: Add parameter to disable automatic group creation in IniLoadFile::GetGroup(). 2011-03-03 20:55:06 +00:00
alberth 722296e797 (svn r22168) -Codechange: Move ini file IO and file error reporting to virtual functions. 2011-03-03 20:53:09 +00:00
alberth d19a9f5df5 (svn r22167) -Codechange: Extract IniLoadFile base class for loading ini files out of IniFile. 2011-03-03 20:50:24 +00:00