From owner-svn-src-all@freebsd.org Thu Sep 7 07:30:07 2017 Return-Path: Delivered-To: svn-src-all@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id B6822E0DAEA; Thu, 7 Sep 2017 07:30:07 +0000 (UTC) (envelope-from imp@FreeBSD.org) Received: from repo.freebsd.org (repo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mx1.freebsd.org (Postfix) with ESMTPS id 4AFEA63486; Thu, 7 Sep 2017 07:30:07 +0000 (UTC) (envelope-from imp@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id v877U6rZ006915; Thu, 7 Sep 2017 07:30:06 GMT (envelope-from imp@FreeBSD.org) Received: (from imp@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id v877U6xE006912; Thu, 7 Sep 2017 07:30:06 GMT (envelope-from imp@FreeBSD.org) Message-Id: <201709070730.v877U6xE006912@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: imp set sender to imp@FreeBSD.org using -f From: Warner Losh Date: Thu, 7 Sep 2017 07:30:06 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r323258 - in head/sys/boot/efi: boot1 include libefi X-SVN-Group: head X-SVN-Commit-Author: imp X-SVN-Commit-Paths: in head/sys/boot/efi: boot1 include libefi X-SVN-Commit-Revision: 323258 X-SVN-Commit-Repository: base MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-all@freebsd.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: "SVN commit messages for the entire src tree \(except for " user" and " projects" \)" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 07 Sep 2017 07:30:08 -0000 Author: imp Date: Thu Sep 7 07:30:05 2017 New Revision: 323258 URL: https://svnweb.freebsd.org/changeset/base/323258 Log: ucs2len Rename boot1's wcslen to ucs2len, which we can't use in userland because wchar in userland is unsigned, not short. Move it into efichar.c. Also spell '* 2' as '* sizeof(efi_char)' and add 1 for the trailing NUL to transition the FreeBSD boot env vars to being NUL terminated on the same line... Sponsored by: Netflix Modified: head/sys/boot/efi/boot1/boot1.c head/sys/boot/efi/include/efichar.h head/sys/boot/efi/libefi/efichar.c Modified: head/sys/boot/efi/boot1/boot1.c ============================================================================== --- head/sys/boot/efi/boot1/boot1.c Thu Sep 7 07:24:22 2017 (r323257) +++ head/sys/boot/efi/boot1/boot1.c Thu Sep 7 07:30:05 2017 (r323258) @@ -80,17 +80,6 @@ Free(void *buf, const char *file __unused, int line __ (void)BS->FreePool(buf); } -static int -wcslen(const CHAR16 *str) -{ - int i; - - i = 0; - while (*str++) - i++; - return i; -} - static EFI_STATUS efi_setenv_freebsd_wcs(const char *varname, CHAR16 *valstr) { @@ -103,7 +92,7 @@ efi_setenv_freebsd_wcs(const char *varname, CHAR16 *va return (EFI_OUT_OF_RESOURCES); rv = RS->SetVariable(var, &FreeBSDBootVarGUID, EFI_VARIABLE_BOOTSERVICE_ACCESS | EFI_VARIABLE_RUNTIME_ACCESS, - wcslen(valstr) * 2, valstr); + (ucs2len(valstr) + 1) * sizeof(efi_char), valstr); free(var); return (rv); } Modified: head/sys/boot/efi/include/efichar.h ============================================================================== --- head/sys/boot/efi/include/efichar.h Thu Sep 7 07:24:22 2017 (r323257) +++ head/sys/boot/efi/include/efichar.h Thu Sep 7 07:30:05 2017 (r323258) @@ -31,5 +31,6 @@ int ucs2_to_utf8(const efi_char *, char **); int utf8_to_ucs2(const char *, efi_char **, size_t *); +int ucs2len(const efi_char *); #endif /* _BOOT_EFI_EFICHAR_H_ */ Modified: head/sys/boot/efi/libefi/efichar.c ============================================================================== --- head/sys/boot/efi/libefi/efichar.c Thu Sep 7 07:24:22 2017 (r323257) +++ head/sys/boot/efi/libefi/efichar.c Thu Sep 7 07:30:05 2017 (r323258) @@ -42,6 +42,17 @@ __FBSDID("$FreeBSD$"); #include "efichar.h" +int +ucs2len(const efi_char *str) +{ + int i; + + i = 0; + while (*str++) + i++; + return i; +} + /* * If nm were converted to utf8, what what would strlen * return on the resulting string?