From owner-p4-projects@FreeBSD.ORG Thu Dec 20 13:07:13 2007 Return-Path: Delivered-To: p4-projects@freebsd.org Received: by hub.freebsd.org (Postfix, from userid 32767) id 31D1C16A419; Thu, 20 Dec 2007 13:07:13 +0000 (UTC) Delivered-To: perforce@FreeBSD.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 6230E16A41A for ; Thu, 20 Dec 2007 13:07:12 +0000 (UTC) (envelope-from gcooper@FreeBSD.org) Received: from repoman.freebsd.org (repoman.freebsd.org [IPv6:2001:4f8:fff6::29]) by mx1.freebsd.org (Postfix) with ESMTP id 4E32E13C4EB for ; Thu, 20 Dec 2007 13:07:12 +0000 (UTC) (envelope-from gcooper@FreeBSD.org) Received: from repoman.freebsd.org (localhost [127.0.0.1]) by repoman.freebsd.org (8.14.1/8.14.1) with ESMTP id lBKD7CgP065585 for ; Thu, 20 Dec 2007 13:07:12 GMT (envelope-from gcooper@FreeBSD.org) Received: (from perforce@localhost) by repoman.freebsd.org (8.14.1/8.14.1/Submit) id lBKD7BD7065582 for perforce@freebsd.org; Thu, 20 Dec 2007 13:07:11 GMT (envelope-from gcooper@FreeBSD.org) Date: Thu, 20 Dec 2007 13:07:11 GMT Message-Id: <200712201307.lBKD7BD7065582@repoman.freebsd.org> X-Authentication-Warning: repoman.freebsd.org: perforce set sender to gcooper@FreeBSD.org using -f From: Garrett Cooper To: Perforce Change Reviews Cc: Subject: PERFORCE change 131306 for review X-BeenThere: p4-projects@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: p4 projects tree changes List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 20 Dec 2007 13:07:13 -0000 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;