From owner-svn-src-head@FreeBSD.ORG Wed Jul 2 19:31:50 2014 Return-Path: Delivered-To: svn-src-head@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) (using TLSv1 with cipher ADH-AES256-SHA (256/256 bits)) (No client certificate requested) by hub.freebsd.org (Postfix) with ESMTPS id 0C79A9EF; Wed, 2 Jul 2014 19:31:50 +0000 (UTC) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:1900:2254:2068::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 EDC8A2941; Wed, 2 Jul 2014 19:31:49 +0000 (UTC) Received: from svn.freebsd.org ([127.0.1.70]) by svn.freebsd.org (8.14.8/8.14.8) with ESMTP id s62JVnaX045911; Wed, 2 Jul 2014 19:31:49 GMT (envelope-from emaste@svn.freebsd.org) Received: (from emaste@localhost) by svn.freebsd.org (8.14.8/8.14.8/Submit) id s62JVnM5045910; Wed, 2 Jul 2014 19:31:49 GMT (envelope-from emaste@svn.freebsd.org) Message-Id: <201407021931.s62JVnM5045910@svn.freebsd.org> From: Ed Maste Date: Wed, 2 Jul 2014 19:31:49 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r268172 - head/usr.bin/vtfontcvt X-SVN-Group: head MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-head@freebsd.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: SVN commit messages for the src tree for head/-current List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 02 Jul 2014 19:31:50 -0000 Author: emaste Date: Wed Jul 2 19:31:49 2014 New Revision: 268172 URL: http://svnweb.freebsd.org/changeset/base/268172 Log: vtfontcvt: correct width calculation (.hex files and commandline) MFC after: 1 week Sponsored by: The FreeBSD Foundation Modified: head/usr.bin/vtfontcvt/vtfontcvt.c Modified: head/usr.bin/vtfontcvt/vtfontcvt.c ============================================================================== --- head/usr.bin/vtfontcvt/vtfontcvt.c Wed Jul 2 19:25:49 2014 (r268171) +++ head/usr.bin/vtfontcvt/vtfontcvt.c Wed Jul 2 19:31:49 2014 (r268172) @@ -285,6 +285,16 @@ parse_bdf(FILE *fp, unsigned int map_idx return (0); } +static void +set_width(int w) +{ + + if (w <= 0 || w > 128) + errx(1, "invalid width %d", w); + width = w; + wbytes = howmany(width, 8); +} + static int parse_hex(FILE *fp, unsigned int map_idx) { @@ -300,12 +310,12 @@ parse_hex(FILE *fp, unsigned int map_idx if (strncmp(ln, "# Height: ", 10) == 0) { height = atoi(ln + 10); } else if (strncmp(ln, "# Width: ", 9) == 0) { - width = atoi(ln + 9); + set_width(atoi(ln + 9)); } else if (sscanf(ln, "%4x:", &curchar)) { p = ln + 5; chars_per_row = strlen(p) / height; dwidth = width; - if (chars_per_row / 2 > width / 8) + if (chars_per_row / 2 > (width + 7) / 8) dwidth *= 2; /* Double-width character. */ snprintf(fmt_str, sizeof(fmt_str), "%%%ux", chars_per_row); @@ -528,12 +538,7 @@ main(int argc, char *argv[]) verbose = 1; break; case 'w': - val = atoi(optarg); - if (val <= 0 || val > 128) { - errx(1, "Invalid width %d", val); - return (1); - } - width = val; + set_width(atoi(optarg)); break; case '?': default: