From 6dd92005030d9b7daccd18f0bcd949117274432d Mon Sep 17 00:00:00 2001 From: Misa Date: Sun, 13 Nov 2022 19:03:26 -0800 Subject: [PATCH] Fix up style in `_Mix_ParseTime` This does the following: - Const-qualify variables if they are not modified - Place each statement onto their own separate lines - Place the asterisk with the type instead of the variable name - Combine declarations and initializations where possible --- desktop_version/src/Music.cpp | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/desktop_version/src/Music.cpp b/desktop_version/src/Music.cpp index 9de18024..67de4947 100644 --- a/desktop_version/src/Music.cpp +++ b/desktop_version/src/Music.cpp @@ -524,11 +524,11 @@ end: } } - static int _Mix_ParseTime(char *time, long samplerate_hz) + static int _Mix_ParseTime(char* time, const long samplerate_hz) { - char *num_start, *p; - Sint64 result; - char c; + char* num_start = time; + char* p; + Sint64 result = 0; int val; /* Time is directly expressed as a sample position */ @@ -537,15 +537,14 @@ end: return SDL_strtoll(time, NULL, 10); } - result = 0; - num_start = time; - for (p = time; *p != '\0'; ++p) { if (*p == '.' || *p == ':') { - c = *p; *p = '\0'; - if ((val = SDL_atoi(num_start)) < 0) + const char c = *p; + *p = '\0'; + val = SDL_atoi(num_start); + if (val < 0) { return -1; } @@ -556,7 +555,7 @@ end: if (*p == '.') { - double val_f = SDL_atof(p); + const double val_f = SDL_atof(p); if (val_f < 0) { return -1; @@ -565,7 +564,8 @@ end: } } - if ((val = SDL_atoi(num_start)) < 0) + val = SDL_atoi(num_start); + if (val < 0) { return -1; }