Date: Thu, 20 Dec 2007 13:07:11 GMT From: Garrett Cooper <gcooper@FreeBSD.org> To: Perforce Change Reviews <perforce@FreeBSD.org> Subject: PERFORCE change 131306 for review Message-ID: <200712201307.lBKD7BD7065582@repoman.freebsd.org>
next in thread | raw e-mail | index | archive | help
http://perforce.freebsd.org/chv.cgi?CH=131306 Change 131306 by gcooper@shiina-ibook on 2007/12/20 13:07:08 Zap some more todo's.. Affected files ... .. //depot/projects/soc2007/revised_fbsd_pkgtools/pkg_revised/v2/contrib/libpkg/pkg_db_match.c#2 edit .. //depot/projects/soc2007/revised_fbsd_pkgtools/pkg_revised/v2/contrib/libpkg/pkgfile.c#3 edit Differences ... ==== //depot/projects/soc2007/revised_fbsd_pkgtools/pkg_revised/v2/contrib/libpkg/pkg_db_match.c#2 (text+ko) ==== @@ -221,7 +221,6 @@ static int pkg_match_name(struct pkg *pkg, const void *data) { - /** @todo pkg_match_name() can be public as it has no custom struct */ int i; /* Use a union as I couldn't cast a const void * to a const char ** */ union { @@ -288,4 +287,4 @@ /** * @} - */+ */ ==== //depot/projects/soc2007/revised_fbsd_pkgtools/pkg_revised/v2/contrib/libpkg/pkgfile.c#3 (text+ko) ==== @@ -400,7 +400,6 @@ /** * @brief Reads up to length bytes from a file * @return A string containing the data or NULL - * @todo Change to return "const char *" and not do the strdup */ const char * pkgfile_get_data(struct pkgfile *file) @@ -420,9 +419,8 @@ return file->name; case pkgfile_hardlink: assert(file->loc == pkgfile_loc_mem); - if (file->loc == pkgfile_loc_mem) { + if (file->loc == pkgfile_loc_mem) return file->data; - } break; case pkgfile_regular: @@ -431,17 +429,31 @@ /* Load the file to the data pointer */ if (file->data == NULL && file->length > 0) { file->data = malloc(file->length); + + int read_amt; + if (file->data == NULL) return NULL; + /* - * Read up to length bytes - * from the file to data + * Read up to length bytes from the file to data + */ + read_amt = fread(file->data, sizeof(char), + file->length, file->fd); + /* + * If the lengths don't match, print out an error and bail.. */ - /** @todo check length < size left in file */ - fread(file->data, 1, file->length, file->fd); + if (read_amt != file->length) { + fprintf(stderr, "Number of fread(3) elements (%d) " + "!= file length (%d)", read_amt, + (int) file->length); + return NULL; + } + } } + /** FALL-THROUGH **/ case pkgfile_symlink: return file->data; @@ -699,7 +711,11 @@ const char * pkgfile_find_line(struct pkgfile *file, const char *line) { - char *buf; + char *buf, *new_buf; + + const int line_length = strlen(line); + + int buf_remaining; if (file == NULL || line == NULL) return NULL; @@ -712,14 +728,30 @@ pkgfile_get_data(file); buf = file->data; - /** @todo Change the length of the buffer left on each iteration */ - while ((buf = memmem(buf, file->length, line, strlen(line))) != NULL) { + + buf_remaining = file->length; + + while (0 < buf_remaining && buf != NULL) { + + new_buf = memmem(buf, file->length, line, line_length); + + if (new_buf == NULL) + break; + + buf_remaining -= (new_buf - buf); + + if (buf == NULL) + break; + + buf = new_buf; + /* Check the found line is complete */ if ((buf == file->data || buf[-1] == '\n') && - (buf + strlen(line) == file->data + file->length || - buf[strlen(line)] == '\n')) { + (buf + line_length == file->data + file->length || + buf[line_length] == '\n')) { break; } + } return buf;
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?200712201307.lBKD7BD7065582>