User Tag List

Results 1 to 1 of 1

Thread: Is something wrong with strip_extra_spaces?

  1. #1
    Octorok Asuna Yuuki Nagato's Avatar
    Join Date
    Jan 2024
    Posts
    491
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    vBActivity - Stats
    Points
    56
    Level
    2
    vBActivity - Bars
    Lv. Percent
    60%

    Is something wrong with strip_extra_spaces?

    In zq_strings.cpp we have:

    Code:
    // Don't actually use this to strip spaces.
    char *strip_extra_spaces(char *string)
    Why shouldn't I call this function? It is being called from void refresh in zquest.cpp, should we refactor that?

  2. #2
    Octorok Asuna Yuuki Nagato's Avatar
    Join Date
    Jan 2024
    Posts
    491
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    vBActivity - Stats
    Points
    56
    Level
    2
    vBActivity - Bars
    Lv. Percent
    60%
    One problem is that strip_extra_spaces does not check the return value of malloc.

  3. #3
    Octorok Asuna Yuuki Nagato's Avatar
    Join Date
    Jan 2024
    Posts
    491
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    vBActivity - Stats
    Points
    56
    Level
    2
    vBActivity - Bars
    Lv. Percent
    60%
    strlen is called many times in loops as well, no need to keep doing that if the length hasn't changed.

  4. #4
    Octorok Asuna Yuuki Nagato's Avatar
    Join Date
    Jan 2024
    Posts
    491
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    vBActivity - Stats
    Points
    56
    Level
    2
    vBActivity - Bars
    Lv. Percent
    60%
    Note that there is an overload of strip_extra_spaces taking a std::string&

    The char* overload is called by MsgString in zq_strings.cpp, which allocates a 71 character array on the heap to pass to strip_extra_spaces. It's probably fine to allocate that on the stack instead.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
About us
Armageddon Games is a game development group founded in 1997. We are extremely passionate about our work and our inspirations are mostly drawn from games of the 8-bit and 16-bit era.
Social