Add missing comment for the offset argument of tokenize. Add error checko on the offset.
This commit is contained in:
@@ -174,6 +174,7 @@ char *strtok_r(char *str, const char *delim, char **saveptr);
|
||||
/// parsed token in buffer. The pointer `string` will be modified.
|
||||
/// @param string cursor used to parse the string, it will be modified.
|
||||
/// @param separators the list of separators we are using.
|
||||
/// @param offset the offset character from which we start extracting the next token.
|
||||
/// @param buffer the buffer where we save the parsed token.
|
||||
/// @param buflen the length of the buffer.
|
||||
/// @return 1 if we still have things to parse, 0 if we finished parsing.
|
||||
|
||||
@@ -61,7 +61,7 @@ int unlink(const char *path);
|
||||
int symlink(const char *linkname, const char *path);
|
||||
|
||||
/// @brief Read the symbolic link, if present.
|
||||
/// @param file the file for which we want to read the symbolic link information.
|
||||
/// @param path the file for which we want to read the symbolic link information.
|
||||
/// @param buffer the buffer where we will store the symbolic link path.
|
||||
/// @param bufsize the size of the buffer.
|
||||
/// @return The number of read characters on success, -1 otherwise and errno is set to indicate the error.
|
||||
|
||||
+3
-2
@@ -221,7 +221,7 @@ char *strpbrk(const char *string, const char *control)
|
||||
int tokenize(const char *string, char *separators, size_t *offset, char *buffer, ssize_t buflen)
|
||||
{
|
||||
// If we reached the end of the parsed string, stop.
|
||||
if (string[*offset] == 0) {
|
||||
if ((*offset >= buflen) || (string[*offset] == 0)) {
|
||||
return 0;
|
||||
}
|
||||
// Keep copying character until we either reach 1) the end of the buffer, 2) a
|
||||
@@ -238,7 +238,8 @@ int tokenize(const char *string, char *separators, size_t *offset, char *buffer,
|
||||
}
|
||||
// Save the character.
|
||||
*buffer = string[*offset];
|
||||
// Advance the offset, decrese the available size in the buffer, and advance the buffer.
|
||||
// Advance the offset, decrese the available size in the buffer, and advance
|
||||
// the buffer.
|
||||
++(*offset), --buflen, ++buffer;
|
||||
} while ((buflen > 0) && (string[*offset] != 0));
|
||||
// Close the buffer.
|
||||
|
||||
@@ -221,7 +221,7 @@ char *strpbrk(const char *string, const char *control)
|
||||
int tokenize(const char *string, char *separators, size_t *offset, char *buffer, ssize_t buflen)
|
||||
{
|
||||
// If we reached the end of the parsed string, stop.
|
||||
if (string[*offset] == 0) {
|
||||
if ((*offset >= buflen) || (string[*offset] == 0)) {
|
||||
return 0;
|
||||
}
|
||||
// Keep copying character until we either reach 1) the end of the buffer, 2) a
|
||||
|
||||
Reference in New Issue
Block a user