source@mandoc.bsd.lv
 help / color / mirror / Atom feed
From: kristaps@mdocml.bsd.lv
To: source@mdocml.bsd.lv
Subject: mdocml: Make mchars_num2char() return a char like it says.
Date: Sat, 30 Apr 2011 18:24:31 -0400 (EDT)	[thread overview]
Message-ID: <201104302224.p3UMOViH020740@krisdoz.my.domain> (raw)

Log Message:
-----------
Make mchars_num2char() return a char like it says.

Modified Files:
--------------
    mdocml:
        chars.c
        html.c
        mandoc.h
        term.c

Revision Data
-------------
Index: term.c
===================================================================
RCS file: /usr/vhosts/mdocml.bsd.lv/cvs/mdocml/term.c,v
retrieving revision 1.185
retrieving revision 1.186
diff -Lterm.c -Lterm.c -u -p -r1.185 -r1.186
--- term.c
+++ term.c
@@ -348,11 +348,10 @@ term_vspace(struct termp *p)
 static void
 numbered(struct termp *p, const char *word, size_t len)
 {
-	const char	*rhs;
+	char		 c;
 
-	rhs = mchars_num2char(word, len);
-	if (rhs) 
-		encode(p, rhs, 1);
+	if ('\0' != (c = mchars_num2char(word, len)))
+		encode(p, &c, 1);
 }
 
 
Index: chars.c
===================================================================
RCS file: /usr/vhosts/mdocml.bsd.lv/cvs/mdocml/chars.c,v
retrieving revision 1.38
retrieving revision 1.39
diff -Lchars.c -Lchars.c -u -p -r1.38 -r1.39
--- chars.c
+++ chars.c
@@ -137,23 +137,23 @@ mchars_res2cp(struct mchars *arg, const 
 
 
 /*
- * Numbered character to literal character,
- * represented as a null-terminated string for additional safety.
+ * Numbered character to literal character.
  */
-const char *
+char
 mchars_num2char(const char *p, size_t sz)
 {
 	int		  i;
-	static char	  c[2];
 
 	if (sz > 3)
-		return(NULL);
+		return('\0');
+
 	i = atoi(p);
-	if (i < 0 || i > 255)
-		return(NULL);
-	c[0] = (char)i;
-	c[1] = '\0';
-	return(c);
+	/* 
+	 * FIXME:
+	 * This is wrong.  Anything could be written here!
+	 * This should be carefully screened for possible characters.
+	 */
+	return(i <= 0 || i > 255 ? '\0' : (char)i);
 }
 
 
Index: html.c
===================================================================
RCS file: /usr/vhosts/mdocml.bsd.lv/cvs/mdocml/html.c,v
retrieving revision 1.136
retrieving revision 1.137
diff -Lhtml.c -Lhtml.c -u -p -r1.136 -r1.137
--- html.c
+++ html.c
@@ -212,11 +212,10 @@ print_gen_head(struct html *h)
 static void
 print_num(struct html *h, const char *p, size_t len)
 {
-	const char	*rhs;
+	char		 c;
 
-	rhs = mchars_num2char(p, len);
-	if (rhs)
-		putchar((int)*rhs);
+	if ('\0' != (c = mchars_num2char(p, len)))
+		putchar((int)c);
 }
 
 static void
Index: mandoc.h
===================================================================
RCS file: /usr/vhosts/mdocml.bsd.lv/cvs/mdocml/mandoc.h,v
retrieving revision 1.73
retrieving revision 1.74
diff -Lmandoc.h -Lmandoc.h -u -p -r1.73 -r1.74
--- mandoc.h
+++ mandoc.h
@@ -328,7 +328,7 @@ void		 *mandoc_realloc(void *, size_t);
 enum mandoc_esc	  mandoc_escape(const char **, const char **, int *);
 
 struct mchars	 *mchars_alloc(void);
-const char	 *mchars_num2char(const char *, size_t);
+char	 	  mchars_num2char(const char *, size_t);
 const char	 *mchars_spec2str(struct mchars *, const char *, size_t, size_t *);
 int		  mchars_spec2cp(struct mchars *, const char *, size_t);
 const char	 *mchars_res2str(struct mchars *, const char *, size_t, size_t *);
--
 To unsubscribe send an email to source+unsubscribe@mdocml.bsd.lv

                 reply	other threads:[~2011-04-30 22:24 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=201104302224.p3UMOViH020740@krisdoz.my.domain \
    --to=kristaps@mdocml.bsd.lv \
    --cc=source@mdocml.bsd.lv \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).