unofficial mirror of bug-gnu-emacs@gnu.org 
 help / color / mirror / code / Atom feed
* bug#8601: * 2 -> * 4 typo fix in detect_coding_charset
@ 2011-05-01 18:19 Paul Eggert
  2011-05-01 19:06 ` Andreas Schwab
  2011-05-06  7:29 ` bug#8601: Merged fixes for 8600, 8601, 8602, and (partially) for 8545 Paul Eggert
  0 siblings, 2 replies; 56+ messages in thread
From: Paul Eggert @ 2011-05-01 18:19 UTC (permalink / raw)
  To: 8601; +Cc: Miles Bader

By code inspection it appears that there's a typo in
detect_coding_charset: an index is multiplied by 2
when it should be multiplied by 4.  By bisecting it
appears that this typo was introduced here:

	revno: 84043 [merge]
	committer: Miles Bader <miles@gnu.org>
	timestamp: Fri 2008-02-01 16:01:31 +0000
	message:
	  Merge unicode branch

	  Revision: emacs@sv.gnu.org/emacs--devo--0--patch-1037

so I'll CC: this to Miles.

Here's a proposed patch.  I haven't tested this, as I don't
have the time to fully understand this code.  But from the
description and other uses of code_space, the "* 2" must be
wrong.

=== modified file 'src/coding.c'
--- src/coding.c	2011-04-29 19:47:29 +0000
+++ src/coding.c	2011-05-01 18:05:21 +0000
@@ -5368,8 +5368,8 @@ detect_coding_charset (struct coding_sys
 	      if (src == src_end)
 		goto too_short;
 	      ONE_MORE_BYTE (c);
-	      if (c < charset->code_space[(dim - 1 - idx) * 2]
-		  || c > charset->code_space[(dim - 1 - idx) * 2 + 1])
+	      if (c < charset->code_space[(dim - 1 - idx) * 4]
+		  || c > charset->code_space[(dim - 1 - idx) * 4 + 1])
 		break;
 	    }
 	  if (idx < dim)







^ permalink raw reply	[flat|nested] 56+ messages in thread
* bug#8545: issues with recent doprnt-related changes
@ 2011-04-25  5:46 Paul Eggert
  2011-04-25  9:00 ` Eli Zaretskii
  0 siblings, 1 reply; 56+ messages in thread
From: Paul Eggert @ 2011-04-25  5:46 UTC (permalink / raw)
  To: 8545

This is a followup to Bug#8435.  Eli invited me to review the recent
doprnt-related changes, so here's a quick review:

* doprnt returns size_t.  But Stefan wrote that he prefers sizes to be
  signed values, and doprnt always returns a value that can fit in
  EMACS_INT.  So shouldn't doprnt return EMACS_INT, as it did before?

* doprnt supports only a small subset of the standard printf formats,
  but this subset is not documented.  It's unclear what the subset is.
  Or it's a superset of the subset, with %S and %l?  Anyway, this
  should be documented clearly in the lead comment.

* I suggest that every feature in doprnt be a feature that is actually
  needed and used; this will simplify maintainance.

* Format strings never include embedded null bytes, so there's
  no need for doprnt to support that.

* If the format string is too long, the alloca inside doprnt will
  crash Emacs on some hosts.  I suggest removing the alloca,
  instituting a fixed size limit on format specifiers, and documenting
  that limit.  Since user code cannot ever supply one of these
  formats, that should be good enough.

* The width features of doprnt (e.g., %25s) are never used.  That part
  of the code is still buggy; please see some comments below.  I
  suggest removing it entirely; this will simplify things.  But if not:

  - doprnt mishandles format specifications such as %0.0.0d.
    It passes them off to printf, and this results in undefined
    behavior, near as I can tell.

  - doprnt uses atoi (&fmtcpy[1]), but surely this isn't right if
    there are flags such as '-'.

  - Quite possibly there are other problems in this area, but I
    didn't want to spend further time reviewing a never-used feature.

* In this code, in verror:

      used = doprnt (buffer, size, m, m + mlen, ap);

      /* Note: the -1 below is because `doprnt' returns the number of bytes     
         excluding the terminating null byte, and it always terminates with a   
         null byte, even when producing a truncated message.  */
      if (used < size - 1)
        break;

  I don't see the reason for the "- 1".  If you replace this with:

      used = doprnt (buffer, size, m, m + mlen, ap);

      if (used < size)
        break;

  the code should still work, because, when used < size, the buffer
  should be properly null-terminated.  If it isn't then there's something
  wrong with doprnt, no?

* In this code, in verror:

      else if (size < size_max - 1)
        size = size_max - 1;

  there's no need for the "- 1"s.  Just use this:

      else if (size < size_max)
        size = size_max;

* This code in verror:

      if (buffer == buf)
        buffer = (char *) xmalloc (size);
      else
        buffer = (char *) xrealloc (buffer, size);

  uses xrealloc, which is unnecessarily expensive, as it may copy the
  buffer's contents even though they are entirely garbage here.  Use
  this instead, to avoid the useless copy:

      if (buffer != buf)
        xfree (buffer);
      buffer = (char *) xmalloc (size);





^ permalink raw reply	[flat|nested] 56+ messages in thread

end of thread, other threads:[~2020-09-16  2:01 UTC | newest]

Thread overview: 56+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2011-05-01 18:19 bug#8601: * 2 -> * 4 typo fix in detect_coding_charset Paul Eggert
2011-05-01 19:06 ` Andreas Schwab
2011-05-01 19:25   ` Paul Eggert
2011-05-06  7:29 ` bug#8601: Merged fixes for 8600, 8601, 8602, and (partially) for 8545 Paul Eggert
2020-09-14 12:37   ` bug#8545: " Lars Ingebrigtsen
2020-09-14 18:41     ` Eli Zaretskii
2020-09-16  2:01       ` Paul Eggert
  -- strict thread matches above, loose matches on Subject: below --
2011-04-25  5:46 bug#8545: issues with recent doprnt-related changes Paul Eggert
2011-04-25  9:00 ` Eli Zaretskii
2011-04-25 13:37   ` Stefan Monnier
2011-04-26 20:25     ` Paul Eggert
2011-04-27  1:14       ` Stefan Monnier
2011-04-26  6:02   ` Paul Eggert
2011-04-27 19:34     ` Eli Zaretskii
2011-04-27 23:51       ` Paul Eggert
2011-04-28  1:32         ` Juanma Barranquero
2011-04-28  3:11           ` Paul Eggert
2011-04-28  3:42             ` Juanma Barranquero
2011-04-28  5:06               ` Paul Eggert
2011-04-28  5:15             ` Eli Zaretskii
2011-04-28  5:29               ` Paul Eggert
2011-04-28  6:10                 ` Eli Zaretskii
2011-04-28  6:42                   ` Paul Eggert
2011-04-28  7:26                     ` Eli Zaretskii
2011-04-28  7:54                       ` Paul Eggert
2011-04-28 11:14                         ` Eli Zaretskii
2011-04-29 12:28             ` Richard Stallman
2011-04-29 19:56               ` Eli Zaretskii
2011-04-29 23:49               ` Paul Eggert
2011-04-30 21:03                 ` Richard Stallman
2011-05-01  5:41                   ` Paul Eggert
2011-05-01 23:59                     ` Richard Stallman
2011-05-02  0:23                       ` Paul Eggert
     [not found]                         ` <E1QH37h-0001yM-HR@fencepost.gnu.org>
2011-05-03 20:24                           ` Paul Eggert
2011-05-01  4:25                 ` Jason Rumney
2011-05-01  5:56                   ` Paul Eggert
2011-05-01  8:12                     ` Jason Rumney
2011-05-01 11:02                       ` Andreas Schwab
2011-04-28  5:02           ` Eli Zaretskii
2011-04-28  5:50         ` Eli Zaretskii
     [not found]           ` <4DB9146D.2040702@cs.ucla.edu>
     [not found]             ` <E1QFQVO-0004Dq-6o@fencepost.gnu.org>
     [not found]               ` <4DB9E5FF.9020506@cs.ucla.edu>
2011-04-29 11:16                 ` Eli Zaretskii
2011-04-29 14:41                   ` Paul Eggert
2011-04-29 19:35                     ` Eli Zaretskii
2011-04-29 20:32                       ` Paul Eggert
2011-04-30  8:59                         ` Eli Zaretskii
2011-05-04  7:28                   ` Paul Eggert
2011-05-04  9:52                     ` Eli Zaretskii
2011-05-04 14:56                       ` Paul Eggert
     [not found]                       ` <4DC1692B.1090101@cs.ucla.edu>
2011-05-05 20:36                         ` Eli Zaretskii
     [not found]                         ` <83ei4cnau6.fsf@gnu.org>
2011-05-06 13:33                           ` Stefan Monnier
     [not found]                           ` <jwvsjss2bz3.fsf-monnier+emacs@gnu.org>
2011-05-06 14:41                             ` Paul Eggert
2011-05-06 15:03                             ` Eli Zaretskii
     [not found]                             ` <83vcxnlvl9.fsf@gnu.org>
2011-05-06 17:13                               ` Stefan Monnier
     [not found]                               ` <jwv8vuj21q0.fsf-monnier+emacs@gnu.org>
2011-05-06 19:57                                 ` Eli Zaretskii
     [not found]                                 ` <83k4e3lhzp.fsf@gnu.org>
2011-05-07  3:18                                   ` Stefan Monnier
     [not found]                                   ` <jwvr58byz9s.fsf-monnier+emacs@gnu.org>
2011-05-07  7:55                                     ` Eli Zaretskii

Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs.git

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 read-only IMAP folder(s) and NNTP newsgroup(s).