Skip to content

Commit

Permalink
Use size_t/long to avoid truncation
Browse files Browse the repository at this point in the history
Equivalent changes introduced to redis sds.c via:
redis/redis#4568
  • Loading branch information
bjosv committed Feb 1, 2022
1 parent f8de9a4 commit 066c6de
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions sds.c
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ void sdsfree(sds s) {
* the output will be "6" as the string was modified but the logical length
* remains 6 bytes. */
void sdsupdatelen(sds s) {
int reallen = strlen(s);
size_t reallen = strlen(s);
sdssetlen(s, reallen);
}

Expand Down Expand Up @@ -580,7 +580,7 @@ sds sdscatprintf(sds s, const char *fmt, ...) {
*/
sds sdscatfmt(sds s, char const *fmt, ...) {
const char *f = fmt;
int i;
long i;
va_list ap;

va_start(ap,fmt);
Expand Down Expand Up @@ -755,14 +755,14 @@ int sdsrange(sds s, ssize_t start, ssize_t end) {

/* Apply tolower() to every character of the sds string 's'. */
void sdstolower(sds s) {
int len = sdslen(s), j;
size_t len = sdslen(s), j;

for (j = 0; j < len; j++) s[j] = tolower(s[j]);
}

/* Apply toupper() to every character of the sds string 's'. */
void sdstoupper(sds s) {
int len = sdslen(s), j;
size_t len = sdslen(s), j;

for (j = 0; j < len; j++) s[j] = toupper(s[j]);
}
Expand Down

0 comments on commit 066c6de

Please sign in to comment.