From 4ae90c798c7bdd46f9f306169df6064c469783c3 Mon Sep 17 00:00:00 2001
From: Kalle Olavi Niemitalo <kon@iki.fi>
Date: Sun, 31 Dec 2006 09:49:13 +0200
Subject: [PATCH 01/21] Bug 919, mem_mmap_realloc: Don't overflow the buffer
 when shrinking it.

The bug was possible only #ifndef HAVE_MREMAP, thus not on Linux.
---
 src/util/memory.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/src/util/memory.c b/src/util/memory.c
index 81dfbc82a..78ef23d23 100644
--- a/src/util/memory.c
+++ b/src/util/memory.c
@@ -187,7 +187,7 @@ mem_mmap_realloc(void *p, size_t old_size, size_t new_size)
 		void *p2 = mem_mmap_alloc(new_size);
 
 		if (p2) {
-			memcpy(p2, p, old_size);
+			memcpy(p2, p, MIN(old_size, new_size));
 			mem_mmap_free(p, old_size);
 			return p2;
 		}

From bb04bd6a4a4c1b11b7c85090d9369b34c14dc353 Mon Sep 17 00:00:00 2001
From: Kalle Olavi Niemitalo <kon@iki.fi>
Date: Mon, 1 Jan 2007 15:55:10 +0200
Subject: [PATCH 02/21] Lots of NEWS.  All important and many unimportant
 changes are listed.

More work will be needed before the release to shorten this list so
that users will actually bother to read it.
---
 NEWS | 260 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++-
 1 file changed, 257 insertions(+), 3 deletions(-)

diff --git a/NEWS b/NEWS
index b98c48302..5a140687c 100644
--- a/NEWS
+++ b/NEWS
@@ -8,9 +8,263 @@ file for details.
 ELinks now:
 -----------
 
-* Native FSP protocol support (replaces CGI program in contrib/fsp/)
-* SEE Ecmascript backend
-* Minimalistic RSS renderer
+This list now contains all the important changes from ELinks 0.11.0 to
+ELinks 0.12.GIT (4d10c3fb8c2c4945fd9dba757b32a96ed16fe6a4).  The next
+step will be to scan through Bugzilla and look for bug numbers that
+were not mentioned in related commit messages.
+
+The list no doubt includes several changes that are not really
+important enough.  Please move them to the separate "should be removed
+from NEWS" list below, or coalesce several changes into one entry (but
+do list all bug numbers).  It might be a good idea to sort the entries
+roughly in decreasing order of importance.
+
+* Miscellaneous
+  - (bugfix) If ELinks logs debug information to a file, it now opens
+    that in binary mode.
+  - (bugfix) Use PF_* instead of AF_* as first parameter of socket(2).
+  - (enhancement 752) Documentation updates
+  - (enhancement 381) Reduce memory consumption of codepages and some
+    other arrays.
+  - (bugfix) Secure file saving: restore umask after _all_ failure
+    conditions
+  - (bugfix 830) Fix misparsing of -remote URLs containing parenthesis.
+  - (bugfix 868) kill_timer from timer->func can crash check_timers.
+  - (enhancement 831) -remote openURL(URL) can include quoted commas.
+  - (enhancement) Reject invalid UTF-8 input from documents and
+    terminals.
+* Changes in terminal support
+  - (new feature) Support for pasting from GNU screen clipboard
+  - (enhancement) Make ELinks FreeBSD friendly. Defined keys used on
+    FreeBSD console
+  - (enhancement) Mouse wheel support on BSD via moused -z 4
+  - (enhancement) Support for mouse wheel over GPM
+  - (experimental, new feature) UTF-8 as terminal charset: not merely
+    UTF-8 I/O of a unibyte codepage as in previous versions.
+    Double-cell (aka fullwidth) and non-BMP characters work too, but
+    combining characters and right-to-left text do not.  The only
+    multibyte charset ELinks can decode is still UTF-8, so if the
+    server outputs e.g. Shift-JIS, you'd better recode with a proxy.
+  - (bugfix) Kill the ESC timer when blocking the terminal.
+  - (bugfix 724) Better parsing of escape sequences and control
+    sequences from the terminal.
+  - (bugfix) Decode UTF-8 only from bytes, not from codes of special
+    keys.
+  - (bugfix) Do not call toupper with potentially out-of-range values.
+  - (new feature) 24-bit truecolor mode
+  - (enhancement) "Resize terminal" tries to use the window size
+    increment.
+  - (new feature) Support Ctrl+Alt+letter key combinations.
+  - (bugfix) Subprocess forked for SIGTSTP calls _exit, not exit.
+  - (new feature 772) Recognize Shift+Tab on Xterm.
+  - (enhancement) Turn terminal transparency off by default.
+  - (bugfix 871) Lock down the numbering of terminal.*.colors
+    regardless of config options.  This change makes elinks.conf
+    portable between different configurations but unfortunately not
+    between this and previous versions.
+* Changes in cookies and bookmarks
+  - (new feature) "Add server" button in the cookie manager.
+  - (enhancement) Tell the user how to move bookmarks.
+  - (bugfix) Fix crash when moving bookmarks out of a folder.
+  - (bugfix) Fixed crash if XBEL bookmark has no title
+  - (bugfix 886) If the user edits or deletes a cookie, mark the
+    cookie list as needing to be saved.
+  - (enhancement 887) Save in cookie manager should save cookies even
+    if unmodified.
+* Changes in the user interface
+  - (new feature) Internal clipboard support
+  - (enhancement) Place the cursor on the current listbox item, to
+    help screen readers
+  - (enhancement) Localization updates
+  - (bugfix 355) Add documents displayed via "What to do" dialog to
+    globhist
+  - (new feature) Autocreate directories needed to download a file.
+  - (new feature) Option ui.show_menu_bar_always
+  - (new feature) Option ui.tabs moves the tab bar to the top.
+  - (bugfix) Fix searching in menus past unselectable items.
+  - (bugfix) Fix crash with empty File extensions menu.
+  - (new feature) New actions: kill-word-back, move-backward-word,
+    move-forward-word
+  - (bugfix) Use internal OFF_T_FORMAT instead of PRId64
+  - (bugfix) Two small fixes in the authentication dialog.
+  - (enhancement) Ctrl+characters don't trigger hotkeys in menus and
+    dialogs.
+  - (bugfix 396) Never show empty filename in the what-to-do dialog
+* Changes in support for URI schemes, protocols, caching, and encodings
+  - (workaround 841) SMB is now disabled because of CVE-2006-5925.
+  - (new feature) Native FSP protocol support (replaces CGI program in
+    contrib/fsp/)
+  - (new feature) Local CGI
+  - (experimental, bugfix) Gopher changes, including crash fixes
+  - (enhancement) FTP handler parses file sizes better
+  - (bugfix) Fixes cache-control issue. See elinks-users mail from 28 Oct 2005
+  - (new feature) LZMA decompression
+  - (bugfix) Local files in a directory whose name contained + were
+    unreachable.
+  - (new feature) HTTP negotiate-auth using GSSAPI
+  - (bugfix 769) HTTP digest auth computed MD5 from insufficient input.
+  - (bugfix 770) Download resuming simply restarts the download
+  - (bugfix) Fix IPv4 DNS lookup bug
+  - (bugfix) Fix null-pointer crash caused by malformed $HTTP_PROXY.
+  - (enhancement) If-Modified-Since and If-None-Match
+  - (bugfix) gzip_read: always call gzclearerr
+  - (bugfix 107) Recognize "localhost" in file: URIs.
+  - (bugfix 729) Fix crashes with various bogus BitTorrent URLs.
+  - (bugfix 756) "assertion (cached)->object.refcount >= 0 failed"
+    after HTTP proxy was changed
+  - (bugfix 899, Debian 403139) Fix size handling in FTP directory
+    listings.
+* Changes in parsing and rendering of HTML (without DOM)
+  - (enhancement) The list of SGML character entities has been updated
+    from unicode.org.  However, it still isn't subsetted per DTD like
+    it probably should be.
+  - (new feature) Add support for forcing wrapping at the screen boundary
+  - (bugfix 741) HTML comments shouldn't be evaluated inside STYLE elements
+  - (bugfix) Use frame->name instead of target avoiding possible segfault.
+  - (bugfix 284) Render closing parentheses for HTML elements SUB, SUP
+    in the same line; don't let them fall to the next.
+  - (enhancement) Show quote characters for HTML element Q, rather
+    than italics.
+  - (enhancement) Add support for parsing space separated CSS class
+    attribute values
+  - (enhancement 767) HTML meta refresh finds the URL even without "URL=".
+  - (enhancement 396) If the server doesn't say what the Content-Type is
+    but the data contains "<html>", assume it is text/html.
+  - (bugfix 387) Treat &#013; inside <pre>...</pre> as a newline.
+* Changes in parsing and rendering of non-HTML content-types
+  - (new feature) If a mailcap entry indicates copiousoutput, ELinks
+    itself acts as a pager.
+  - (new feature) Let plain text change colors with ESC [ 31 m or
+    similar control sequences.
+* Changes in the document viewer and tabs
+  - (new feature) Highlight links as one enters link prefixes.
+  - (new feature) Backspace backs out the last digit of the prefix.
+  - (bugfix) Tabs opened by -remote now go behind existing dialogs.
+  - (new feature) -dump-color-mode
+  - (bugfix) Fix accesskeys so that they work when priority is 0
+  - (enhancement) Text type-ahead searching: don't follow current link
+    on enter
+  - (bugfix) Take the terminal charset in account when comparing
+    accesskeys.
+  - (enhancement) Display accesskeys as e.g. (Alt-f), not just (f).
+  - (bugfix) Decode the fragment identifier extracted from the URI
+    when looking it up
+  - (bugfix 908) radio button writes via a dangling pointer (potential
+    crash)
+* Changes in user scripting
+  - (bugfix, Gentoo 121247) Ruby: Fix segfaults.
+  - (enhancement) Guile: Read hooks.scm rather than internal-hooks.scm.
+    (Keep reading user-hooks.scm, too.)
+  - (bugfix) Lua: current_document_formatted now works.
+  - (bugfix) Lua: Don't write to the string returned by lua_tostring.
+  - (experimental, new feature, bugfix) Python: Many additions and
+    bug fixes.
+  - (bugfix) SMJS: Don't complain about a missing hooks.js on startup.
+  - (new feature) SMJS: The elinks.preformat_html hook gets a second
+    argument: a view_state object with .uri and .plain properties.
+  - (enhancement) SMJS: elinks.alert no longer displays as an "error".
+  - (new feature) SMJS: New properties elinks.action, elinks.globhist,
+    elinks.vs.
+  - (new feature) SMJS: New function elinks.load_uri.
+  - (new feature) SMJS: New method elinks.execute.
+  - (enhancement) SMJS: Garbage-collect SMJS objects before flushing
+    caches.
+  - (bugfix 870) SMJS: Don't panic if a property ID is unrecognized.
+    (The bug also affected SMJS on web pages, but that's experimental.)
+  - (bitrot) Perl: Don't assume POPpx stores the length to n_a.
+  - (bugfix) Perl: Fix pre_format_html hook wrt. binary files.
+* Build system and compile-time errors (ignore if you don't build ELinks)
+  - (bugfix) Fixed some bugs about compiling outside the source
+    directory.
+  - (bugfix) Don't use cmp -b, which FreeBSD doesn't support.
+  - (bugfix) Don't include <sys/param.h> for MIN and MAX because it
+    may interfere with CONFIG_IPV6 on Linux.
+  - (bugfix) When the configure script cleans old object files, this
+    no longer causes it to loop.
+  - (new feature) --with-python=DIRECTORY, --with-gc=DIRECTORY
+  - (bugfix) Include <sys/types.h> and fix compilation on an old
+    PPC/Debian system
+  - (bitrot) Fix compilation under gcc 4.x. Backported from gentoo portage.
+  - (bitrot) Update SpiderMonkey configure check Debian compatibility
+  - (new feature) Tiny C Compiler support
+  - (experimental, new feature) Native Win32 port
+  - (enhancement) If make -k was used and a sub-Make fails, build the
+    rest before propagating.
+  - (bitrot 768) Look for e.g. -lpython2.4 rather than -lpython.
+  - (enhancement) Avoid compilation of vernum.c in 'make install'
+  - (bugfix) Don't use $(AM_CFLAGS) anymore.  Use $(CPPFLAGS) instead.
+  - (bugfix) Fix compilation on Minix3.
+  - (new feature) make uninstall
+  - (bitrot) Fix two warnings on Mac OS X.
+* (experimental) Changes in ECMAScript support
+  - (enhancement) Disable ECMAScript by default.
+  - (new feature) SEE ECMAScript backend, an alternative to SpiderMonkey.
+  - (new feature) Handling onsubmit
+  - (workaround) window.open remembers the last few URLs and doesn't
+    reopen them when incremental rendering reruns the onload script.
+  - (enhancement) Recognize document.location.href for SMJS.
+  - (enhancement) Better handling of form.action assignments
+  - (bugfix) SMJS: fix segfault on exit.
+  - (enhancement) form[x] looks up controls also by id, not only name.
+  - (new feature) New property input.selectedIndex.
+  - (new feature) Activate link only when onClick returns true.
+  - (enhancement) input.accessKey can be any Unicode character except
+    U+0000.
+  - (new feature) window.setTimeout, window.status
+  - (bugfix 846) Fix potentially exploitable crashes if properties
+    were invoked with "this" objects of unexpected types.
+* (experimental) Changes in SGML/DOM implementation
+  - (new feature) Minimalistic RSS renderer
+  - (enhancement) Source highlighting also recognizes
+    application/xhtml+xml and application/docbook+xml.  It doesn't yet
+    support arbitrary XML though.
+  - (enhancement) Make it possible to use more CSS properties with the
+    source highlighting
+  - (enhancement) Handle <base href=""> for HTML source rendering
+  - (enhancement) Add support for scanning comment endings such as
+    '--!>' correctly
+  - (new feature) Incremental parsing
+  - And more.
+
+The following changes should be removed from NEWS before ELinks 0.12.0
+is released.  They are currently listed here just to show that they
+have already been considered.
+
+* Only partially fixed bugs:
+  - (bugfix 764) int/long type punning in options
+  - (bugfix 725) Fixes version checking for Ruby in 'configure'
+* Fixed bugs that were not in previous versions:
+  - (bugfix) Fix a crash when adding a server in the cookie manager.
+  - (bugfix) cookies: "Add Server" ignores "cookies.accept_policy".
+  - (bugfix) Fix data: protocol.
+  - (bugfix) Properly deselect the main menu instead of crashing
+  - (bugfix 778) ELinks crashes on binary files when
+    document.plain.display_links is set
+  - (bugfix 784) UTF-8 mode misconverts non-ASCII entity in Latin-1
+    document
+  - (bugfix 782) UTF-8 buffer overwritten while in use
+  - (bugfix) switch_to_tab: Prevent "tab number out of range"
+    assertion failure.
+  - (bugfix) Fixed about:
+  - (bugfix 821) I cannot enter national characters in dialog boxes
+  - (bugfix 834) Gzip decompression doesn't work
+  - (bugfix) Fix out-of-bound access to the quote_char buffer
+  - (bugfix 880) Prevent SIGSEGV in init_python when -no-home is used.
+  - (bugfix 788) compile error with --enable-perl
+  - (bugfix 827) Crash with term charset set to Unicode and UTF-8 I/O
+    disabled
+  - (bugfix 826) too small table for double-cell characters
+  - (bugfix 902) crash: "overflow detected realloc()" in realloc_line
+  - (bugfix 912) wrong color in one cell of an HTML input field
+* Reverted changes:
+  - (new feature) document.write, reverted in
+    2c087e52e74528a720621186b91880463e039d50
+  - (enhancement) restore Linux console mode (UTF-8 or not), reverted
+    in 10d72cae7eafa6b90db1c8f303deb200555734c2
+  - (enhancement) wcwidth, reverted in
+    d050cb67aa37390ab938b0a308c7541f19578506
+* Unimportant changes: 
+  - (enhancement) If select fails, save its errno.
 
 ELinks 0.11.0 (Elated):
 -----------------------

From 000883bbbe85be652a1521866c8bdfc88c927b87 Mon Sep 17 00:00:00 2001
From: Kalle Olavi Niemitalo <kon@iki.fi>
Date: Mon, 1 Jan 2007 17:12:45 +0200
Subject: [PATCH 03/21] po/Makefile (update-po): Remove cd $(srcdir).

It has no useful effect here, because Make runs the next command in
a separate shell process that does not inherit the working directory
from this one.
---
 po/Makefile | 1 -
 1 file changed, 1 deletion(-)

diff --git a/po/Makefile b/po/Makefile
index 4d76c8d89..77d62fccd 100644
--- a/po/Makefile
+++ b/po/Makefile
@@ -71,7 +71,6 @@ $(srcdir)$(PACKAGE).pot: $(srcdir)$(POTFILES_ABS_LIST) $(srcdir)perl/gather-acce
 # either <lang> or <lang>.po when calling make. Example: make update-po PO=is
 
 update-po: Makefile $(srcdir)$(PACKAGE).pot
-	@test -z "$(srcdir)" || cd $(srcdir)
 	@$(foreach lang,$(basename $(if $(strip $(PO)),$(PO),$(GMOFILES))), \
 	  echo -n "$(lang): "; \
 	  if $(MSGMERGE) $(srcdir)$(lang).po $(srcdir)$(PACKAGE).pot -o $(lang).new.po; then \

From e45f5a8915b7169e4bfe6475b736adf344f97b8f Mon Sep 17 00:00:00 2001
From: Kalle Olavi Niemitalo <kon@iki.fi>
Date: Mon, 1 Jan 2007 17:18:05 +0200
Subject: [PATCH 04/21] utf8char_len_tab[] is const.

This change moves 256 bytes of data into a read-only section, perhaps
reducing memory consumption when multiple ELinks processes run in parallel.
---
 src/intl/charsets.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/src/intl/charsets.c b/src/intl/charsets.c
index 0d3347131..125f374f3 100644
--- a/src/intl/charsets.c
+++ b/src/intl/charsets.c
@@ -251,7 +251,7 @@ encode_utf8(unicode_val_T u)
 #ifdef CONFIG_UTF8
 /* Number of bytes utf8 character indexed by first byte. Illegal bytes are
  * equal ones and handled different. */
-static char utf8char_len_tab[256] = {
+static const char utf8char_len_tab[256] = {
 	1,1,1,1,1,1,1,1, 1,1,1,1,1,1,1,1, 1,1,1,1,1,1,1,1, 1,1,1,1,1,1,1,1,
 	1,1,1,1,1,1,1,1, 1,1,1,1,1,1,1,1, 1,1,1,1,1,1,1,1, 1,1,1,1,1,1,1,1,
 	1,1,1,1,1,1,1,1, 1,1,1,1,1,1,1,1, 1,1,1,1,1,1,1,1, 1,1,1,1,1,1,1,1,

From 26473f72f59641aa60277f14f703f8a76dda5a82 Mon Sep 17 00:00:00 2001
From: "M. Levinson" <levinsm@users.sourceforge.net>
Date: Sun, 31 Dec 2006 10:00:34 -0500
Subject: [PATCH 05/21] Python: Give goto_url_hook only one argument, like
 follow_url_hook.

On Dec 31, 2006, at 11:30am, Kalle Olavi Niemitalo writes:
>src/scripting/python/hooks.c (script_hook_url) calls hooks as
>goto_url_hook(new-url, current-url) and follow_url_hook(new-url).
>It has a comment saying that the current-url parameter exists
>only for compatibility and that the script can instead use
>elinks.current_url().  However, the current-url parameter was
>added in commit 87e27b9b3e47671484c7eb77d61b75fffc89624f and is
>not in ELinks 0.11.2, so any compatibility problems would only
>hit people who have been using 0.12.GIT snapshots.  Can we remove
>the second parameter now before releasing ELinks 0.12pre1?

The decision isn't up to me, but I think this is a good idea. Here's a
patch that would update the documentation and hooks.py, as well as hooks.c.

FYI, if this patch is applied then anyone who's still trying to use a
goto_url_hook that expects a second argument will get a "Browser scripting
error" dialog box that says:

	An error occurred while running a Python script:

	TypeError: goto_url_hook() takes exactly 2 arguments (1 given)
---
 contrib/python/hooks.py      |  7 ++-----
 doc/python.txt               |  4 +---
 src/scripting/python/hooks.c | 24 +-----------------------
 3 files changed, 4 insertions(+), 31 deletions(-)

diff --git a/contrib/python/hooks.py b/contrib/python/hooks.py
index 0d4151acf..a4726e490 100644
--- a/contrib/python/hooks.py
+++ b/contrib/python/hooks.py
@@ -46,7 +46,7 @@ dumbprefixes = {
         "sd" : "http://www.slashdot.org/"
 }
 
-def goto_url_hook(url, current_url):
+def goto_url_hook(url):
     """Rewrite a URL that was entered in a "Go to URL" dialog box.
 
     This function should return a URL for ELinks to follow, or None if
@@ -55,8 +55,6 @@ def goto_url_hook(url, current_url):
     Arguments:
 
     url -- The URL provided by the user.
-    current_url -- The URL of the document being viewed, or None if no
-            document is being viewed.
 
     """
     if url in dumbprefixes:
@@ -136,13 +134,12 @@ class goto_url_in_new_tab:
     """Prompter that opens a given URL in a new tab."""
     def __init__(self):
         """Prompt for a URL."""
-        self.current_location = elinks.current_url()
         elinks.input_box("Enter URL", self._callback, title="Go to URL")
     def _callback(self, url):
         """Open the given URL in a new tab."""
         if 'goto_url_hook' in globals():
             # Mimic the standard "Go to URL" dialog by calling goto_url_hook().
-            url = goto_url_hook(url, self.current_location) or url
+            url = goto_url_hook(url) or url
         if url:
             elinks.open(url, new_tab=True)
 # The elinks.bind_key() function can be used to create a keystroke binding
diff --git a/doc/python.txt b/doc/python.txt
index baf81357d..a5225150e 100644
--- a/doc/python.txt
+++ b/doc/python.txt
@@ -44,7 +44,7 @@ FUNCTIONS
         
         url -- The URL of the link.
     
-    goto_url_hook(url, current_url)
+    goto_url_hook(url)
         Rewrite a URL that was entered in a "Go to URL" dialog box.
         
         This function should return a URL for ELinks to follow, or None if
@@ -53,8 +53,6 @@ FUNCTIONS
         Arguments:
         
         url -- The URL provided by the user.
-        current_url -- The URL of the document being viewed, or None if no
-                document is being viewed.
     
     pre_format_html_hook(url, html)
         Rewrite the body of a document before it's formatted.
diff --git a/src/scripting/python/hooks.c b/src/scripting/python/hooks.c
index 23a07f07d..9ff63df18 100644
--- a/src/scripting/python/hooks.c
+++ b/src/scripting/python/hooks.c
@@ -15,7 +15,6 @@
 #include "main/event.h"
 #include "protocol/uri.h"
 #include "scripting/python/core.h"
-#include "session/location.h"
 #include "session/session.h"
 #include "util/memory.h"
 #include "util/string.h"
@@ -64,28 +63,7 @@ script_hook_url(va_list ap, void *data)
 
 	python_ses = ses;
 
-	/*
-	 * Historical note: The only reason the goto and follow hooks are
-	 * treated differently is to maintain backwards compatibility for
-	 * people who already have a goto_url_hook() function in hooks.py
-	 * that expects a second argument. If we were starting over from
-	 * scratch, we could treat the goto and follow hooks identically and
-	 * simply pass @url as the sole argument in both cases; the Python
-	 * code for the goto hook no longer needs its @current_url argument
-	 * since it could instead determine the current URL by calling the
-	 * Python interpreter's elinks.current_url() function.
-	 */
-	if (!strcmp(method, "goto_url_hook")) {
-		unsigned char *current_url = NULL;
-
-		if (python_ses && have_location(python_ses))
-			current_url = struri(cur_loc(ses)->vs.uri);
-
-		result = PyObject_CallMethod(python_hooks, method, "ss", *url,
-					     current_url);
-	} else {
-		result = PyObject_CallMethod(python_hooks, method, "s", *url);
-	}
+	result = PyObject_CallMethod(python_hooks, method, "s", *url);
 
 	if (!result || !replace_with_python_string(url, result))
 		alert_python_error();

From d8e8e706d6362dcb65ecefcfb70a3b2cc5e9c63b Mon Sep 17 00:00:00 2001
From: Kalle Olavi Niemitalo <kon@iki.fi>
Date: Mon, 1 Jan 2007 18:58:02 +0200
Subject: [PATCH 06/21] NEWS update

---
 NEWS | 8 +++++---
 1 file changed, 5 insertions(+), 3 deletions(-)

diff --git a/NEWS b/NEWS
index 5a140687c..736158c92 100644
--- a/NEWS
+++ b/NEWS
@@ -9,7 +9,7 @@ ELinks now:
 -----------
 
 This list now contains all the important changes from ELinks 0.11.0 to
-ELinks 0.12.GIT (4d10c3fb8c2c4945fd9dba757b32a96ed16fe6a4).  The next
+ELinks 0.12.GIT (26473f72f59641aa60277f14f703f8a76dda5a82).  The next
 step will be to scan through Bugzilla and look for bug numbers that
 were not mentioned in related commit messages.
 
@@ -114,6 +114,7 @@ roughly in decreasing order of importance.
     after HTTP proxy was changed
   - (bugfix 899, Debian 403139) Fix size handling in FTP directory
     listings.
+  - (bugfix 919) Fixed a buffer overflow when shrinking a cached fragment.
 * Changes in parsing and rendering of HTML (without DOM)
   - (enhancement) The list of SGML character entities has been updated
     from unicode.org.  However, it still isn't subsetted per DTD like
@@ -181,7 +182,7 @@ roughly in decreasing order of importance.
     may interfere with CONFIG_IPV6 on Linux.
   - (bugfix) When the configure script cleans old object files, this
     no longer causes it to loop.
-  - (new feature) --with-python=DIRECTORY, --with-gc=DIRECTORY
+  - (experimental, new feature) --with-python=DIRECTORY, --with-gc=DIRECTORY
   - (bugfix) Include <sys/types.h> and fix compilation on an old
     PPC/Debian system
   - (bitrot) Fix compilation under gcc 4.x. Backported from gentoo portage.
@@ -190,7 +191,8 @@ roughly in decreasing order of importance.
   - (experimental, new feature) Native Win32 port
   - (enhancement) If make -k was used and a sub-Make fails, build the
     rest before propagating.
-  - (bitrot 768) Look for e.g. -lpython2.4 rather than -lpython.
+  - (experimental, bitrot 768) Look for e.g. -lpython2.4 rather than
+    -lpython.
   - (enhancement) Avoid compilation of vernum.c in 'make install'
   - (bugfix) Don't use $(AM_CFLAGS) anymore.  Use $(CPPFLAGS) instead.
   - (bugfix) Fix compilation on Minix3.

From 10f1bd0efc38d07a22ecee4aa29a7b6a8fef0360 Mon Sep 17 00:00:00 2001
From: Kalle Olavi Niemitalo <kon@iki.fi>
Date: Mon, 1 Jan 2007 21:11:46 +0200
Subject: [PATCH 07/21] Document struct conv_table.

---
 src/intl/charsets.h | 14 ++++++++++++++
 1 file changed, 14 insertions(+)

diff --git a/src/intl/charsets.h b/src/intl/charsets.h
index 34c416869..43259de04 100644
--- a/src/intl/charsets.h
+++ b/src/intl/charsets.h
@@ -31,10 +31,24 @@ typedef uint32_t unicode_val_T;
 #define NBSP_CHAR ((unsigned char) 1)
 #define NBSP_CHAR_STRING "\001"
 
+/* How to convert a byte from a source charset.  This is used in an
+ * array (struct conv_table[256]) indexed by the byte value.  */
 struct conv_table {
+	/* 0 if this is the final byte of a character, or 1 if more
+	 * bytes are needed.  */
 	int t;
 	union {
+		/* If @t==0: a null-terminated string that is the
+		 * corresponding character in the target charset.
+		 * Normally, the string is statically allocated.
+		 * However, if the translation table is to UTF-8,
+		 * then the strings in elements 0x80 to 0xFF are
+		 * allocated with mem_alloc.  */
 		unsigned char *str;
+		/* If @t==1: a pointer to a nested conversion table
+		 * (with 256 elements) that describes how to convert
+		 * each possible subsequent byte.  The conversion
+		 * table owns the nested conversion table.  */
 		struct conv_table *tbl;
 	} u;
 };

From 068663783c2c5a3ed014454eb02e97c44d182ac0 Mon Sep 17 00:00:00 2001
From: Kalle Olavi Niemitalo <kon@iki.fi>
Date: Tue, 2 Jan 2007 00:47:38 +0200
Subject: [PATCH 08/21] insert_in_string: Let the seq parameter point to const.

It is the data to be inserted into the other string.
---
 src/util/string.c | 3 ++-
 src/util/string.h | 4 ++--
 2 files changed, 4 insertions(+), 3 deletions(-)

diff --git a/src/util/string.c b/src/util/string.c
index b8865568a..ab486ff46 100644
--- a/src/util/string.c
+++ b/src/util/string.c
@@ -116,7 +116,8 @@ add_to_strn(unsigned char **dst, unsigned char *src)
 }
 
 unsigned char *
-insert_in_string(unsigned char **dst, int pos, unsigned char *seq, int seqlen)
+insert_in_string(unsigned char **dst, int pos,
+		 const unsigned char *seq, int seqlen)
 {
 	int dstlen = strlen(*dst);
 	unsigned char *string = mem_realloc(*dst, dstlen + seqlen + 1);
diff --git a/src/util/string.h b/src/util/string.h
index 4e04bac6f..215f2ba92 100644
--- a/src/util/string.h
+++ b/src/util/string.h
@@ -47,8 +47,8 @@ void add_to_strn(unsigned char **str, unsigned char *src);
 
 /* Inserts @seqlen chars from @seq at position @pos in the @dst string. */
 /* If reallocation of @dst fails it is not touched and NULL is returned. */
-unsigned char *
-insert_in_string(unsigned char **dst, int pos, unsigned char *seq, int seqlen);
+unsigned char *insert_in_string(unsigned char **dst, int pos,
+				const unsigned char *seq, int seqlen);
 
 /* Takes a list of strings where the last parameter _must_ be NULL and
  * concatenates them. */

From 9d14ea4e5a2fc326c7523e51edc35110f1da6a88 Mon Sep 17 00:00:00 2001
From: Kalle Olavi Niemitalo <kon@iki.fi>
Date: Tue, 2 Jan 2007 00:54:14 +0200
Subject: [PATCH 09/21] Document some variables in charsets.c.

---
 src/intl/charsets.c | 7 +++++++
 1 file changed, 7 insertions(+)

diff --git a/src/intl/charsets.c b/src/intl/charsets.c
index 125f374f3..40a5c698e 100644
--- a/src/intl/charsets.c
+++ b/src/intl/charsets.c
@@ -117,6 +117,8 @@ free_translation_table(struct conv_table *p)
 	mem_free(p);
 }
 
+/* A string used in conversion tables when there is no correct
+ * conversion.  */
 static unsigned char *no_str = "*";
 
 static void
@@ -796,6 +798,10 @@ add_utf8(struct conv_table *ct, unicode_val_T u, unsigned char *str)
 		ct[*p].u.str = str;
 }
 
+/* A conversion table from some charset to UTF-8.
+ * If it is from UTF-8 to UTF-8, it converts each byte separately.
+ * Unlike in other translation tables, the strings in elements 0x80 to
+ * 0xFF are allocated dynamically.  */
 struct conv_table utf_table[256];
 int utf_table_init = 1;
 
@@ -857,6 +863,7 @@ get_translation_table_to_utf8(int from)
 	return utf_table;
 }
 
+/* A conversion table between two charsets, where the target is not UTF-8.  */
 struct conv_table table[256];
 static int first = 1;
 

From 161b46a479d7094a4853ef1fcfd0c36ecea196ab Mon Sep 17 00:00:00 2001
From: Kalle Olavi Niemitalo <kon@iki.fi>
Date: Tue, 2 Jan 2007 00:58:38 +0200
Subject: [PATCH 10/21] Make table[] in charsets.c static.

There is no extern declaration for it anywhere.
---
 src/intl/charsets.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/src/intl/charsets.c b/src/intl/charsets.c
index 40a5c698e..0255f066a 100644
--- a/src/intl/charsets.c
+++ b/src/intl/charsets.c
@@ -864,7 +864,7 @@ get_translation_table_to_utf8(int from)
 }
 
 /* A conversion table between two charsets, where the target is not UTF-8.  */
-struct conv_table table[256];
+static struct conv_table table[256];
 static int first = 1;
 
 void

From 2434c180f26194b078ca25b6f228f033a9605bf1 Mon Sep 17 00:00:00 2001
From: Kalle Olavi Niemitalo <kon@iki.fi>
Date: Tue, 2 Jan 2007 01:07:57 +0200
Subject: [PATCH 11/21] Make no_str in charsets.c an array rather than a
 pointer variable.

This ensures that no other string can have the same address.  It
probably never was a problem though, because the strings to which it
can be compared either are allocated from the heap or are in
strings[][] which already has unshared storage.
---
 src/intl/charsets.c | 7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)

diff --git a/src/intl/charsets.c b/src/intl/charsets.c
index 0255f066a..d08c575dc 100644
--- a/src/intl/charsets.c
+++ b/src/intl/charsets.c
@@ -118,8 +118,11 @@ free_translation_table(struct conv_table *p)
 }
 
 /* A string used in conversion tables when there is no correct
- * conversion.  */
-static unsigned char *no_str = "*";
+ * conversion.  This is compared by address and therefore should be a
+ * named array rather than a pointer so that it won't share storage
+ * with any other string literal that happens to have the same
+ * characters.  */
+static unsigned char no_str[] = "*";
 
 static void
 new_translation_table(struct conv_table *p)

From 83f753f750fe9cc276bedb29b6909501e9e3aebb Mon Sep 17 00:00:00 2001
From: Kalle Olavi Niemitalo <kon@iki.fi>
Date: Tue, 2 Jan 2007 01:31:22 +0200
Subject: [PATCH 12/21] conv_table.u.str points to const.

---
 src/intl/charsets.c | 5 +++--
 src/intl/charsets.h | 2 +-
 2 files changed, 4 insertions(+), 3 deletions(-)

diff --git a/src/intl/charsets.c b/src/intl/charsets.c
index d08c575dc..6df8e8ad7 100644
--- a/src/intl/charsets.c
+++ b/src/intl/charsets.c
@@ -813,8 +813,9 @@ free_utf_table(void)
 {
 	int i;
 
+	/* Cast away const.  */
 	for (i = 128; i < 256; i++)
-		mem_free(utf_table[i].u.str);
+		mem_free((unsigned char *) utf_table[i].u.str);
 }
 
 static struct conv_table *
@@ -1191,7 +1192,7 @@ convert_string(struct conv_table *convert_table,
 	/* Iterate ;-) */
 
 	while (charspos < charslen) {
-		unsigned char *translit;
+		const unsigned char *translit;
 
 #define PUTC do { \
 		buffer[bufferpos++] = chars[charspos++]; \
diff --git a/src/intl/charsets.h b/src/intl/charsets.h
index 43259de04..edae15f66 100644
--- a/src/intl/charsets.h
+++ b/src/intl/charsets.h
@@ -44,7 +44,7 @@ struct conv_table {
 		 * However, if the translation table is to UTF-8,
 		 * then the strings in elements 0x80 to 0xFF are
 		 * allocated with mem_alloc.  */
-		unsigned char *str;
+		const unsigned char *str;
 		/* If @t==1: a pointer to a nested conversion table
 		 * (with 256 elements) that describes how to convert
 		 * each possible subsequent byte.  The conversion

From d314348e923a06f8081da37ab82972ad9a2e7e09 Mon Sep 17 00:00:00 2001
From: Kalle Olavi Niemitalo <kon@iki.fi>
Date: Tue, 2 Jan 2007 08:29:08 +0200
Subject: [PATCH 13/21] Make get_entity_string return a pointer to const.

---
 src/intl/charsets.c | 2 +-
 src/intl/charsets.h | 3 ++-
 2 files changed, 3 insertions(+), 2 deletions(-)

diff --git a/src/intl/charsets.c b/src/intl/charsets.c
index 6df8e8ad7..34f326d2e 100644
--- a/src/intl/charsets.c
+++ b/src/intl/charsets.c
@@ -988,7 +988,7 @@ compare_entities(const void *key_, const void *element_)
 	return xxstrcmp(first, second, length);
 }
 
-unsigned char *
+const unsigned char *
 get_entity_string(const unsigned char *str, const int strlen, int encoding)
 {
 #define ENTITY_CACHE_SIZE 10	/* 10 seems a good value. */
diff --git a/src/intl/charsets.h b/src/intl/charsets.h
index edae15f66..db123a240 100644
--- a/src/intl/charsets.h
+++ b/src/intl/charsets.h
@@ -72,7 +72,8 @@ enum nbsp_mode {
 };
 
 struct conv_table *get_translation_table(int, int);
-unsigned char *get_entity_string(const unsigned char *str, const int strlen, int encoding);
+const unsigned char *get_entity_string(const unsigned char *str,
+				       const int strlen, int encoding);
 
 /* The convert_string() name is also used by Samba (version 3.0.3), which
  * provides libnss_wins.so.2, which is called somewhere inside

From 712803bbeb44da7158679d5121570e3a4da4f75a Mon Sep 17 00:00:00 2001
From: Kalle Olavi Niemitalo <kon@iki.fi>
Date: Tue, 2 Jan 2007 20:08:25 +0200
Subject: [PATCH 14/21] Make entity_cache.result point to const.

---
 src/intl/charsets.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/src/intl/charsets.c b/src/intl/charsets.c
index 34f326d2e..4e13819d1 100644
--- a/src/intl/charsets.c
+++ b/src/intl/charsets.c
@@ -964,7 +964,7 @@ struct entity_cache {
 	unsigned int hits;
 	int strlen;
 	int encoding;
-	unsigned char *result;
+	const unsigned char *result;
 	unsigned char str[20]; /* Suffice in any case. */
 };
 
@@ -998,7 +998,7 @@ get_entity_string(const unsigned char *str, const int strlen, int encoding)
 	static unsigned int nb_entity_cache[ENTITY_CACHE_MAXLEN];
 	static int first_time = 1;
 	unsigned int slen = 0;
-	unsigned char *result = NULL;
+	const unsigned char *result = NULL;
 
 	if (strlen <= 0) return NULL;
 

From ef96caad01cb9306a007dc8b05de9c6b775d0e3c Mon Sep 17 00:00:00 2001
From: Kalle Olavi Niemitalo <kon@iki.fi>
Date: Tue, 2 Jan 2007 08:45:02 +0200
Subject: [PATCH 15/21] Make u2cp and u2cp_no_nbsp return a pointer to const.

---
 src/bookmarks/backend/xbel.c | 2 +-
 src/intl/charsets.c          | 4 ++--
 src/intl/charsets.h          | 2 +-
 src/terminal/event.c         | 2 +-
 src/viewer/text/form.c       | 9 +++++----
 5 files changed, 10 insertions(+), 9 deletions(-)

diff --git a/src/bookmarks/backend/xbel.c b/src/bookmarks/backend/xbel.c
index 25ef2cbd6..f7042792c 100644
--- a/src/bookmarks/backend/xbel.c
+++ b/src/bookmarks/backend/xbel.c
@@ -195,7 +195,7 @@ print_xml_entities(struct secure_save_info *ssi, const unsigned char *str)
 				secure_fprintf(ssi, "&#%i;", (int) *str);
 			}
 			else {
-				unsigned char *s = u2cp_no_nbsp(*str, cp);
+				const unsigned char *s = u2cp_no_nbsp(*str, cp);
 
 				if (s) print_xml_entities(ssi, s);
 			}
diff --git a/src/intl/charsets.c b/src/intl/charsets.c
index 4e13819d1..c8f350d9d 100644
--- a/src/intl/charsets.c
+++ b/src/intl/charsets.c
@@ -168,7 +168,7 @@ static const unicode_val_T strange_chars[32] = {
 #define SYSTEM_CHARSET_FLAG 128
 #define is_cp_ptr_utf8(cp_ptr) ((cp_ptr)->aliases == aliases_utf8)
 
-unsigned char *
+const unsigned char *
 u2cp_(unicode_val_T u, int to, enum nbsp_mode nbsp_mode)
 {
 	int j;
@@ -928,7 +928,7 @@ get_translation_table(int from, int to)
 
 		for (i = 128; i < 256; i++) {
 			if (codepages[from].highhalf[i - 0x80] != 0xFFFF) {
-				unsigned char *u;
+				const unsigned char *u;
 
 				u = u2cp(codepages[from].highhalf[i - 0x80], to);
 				if (u) table[i].u.str = u;
diff --git a/src/intl/charsets.h b/src/intl/charsets.h
index db123a240..bee9d14e5 100644
--- a/src/intl/charsets.h
+++ b/src/intl/charsets.h
@@ -138,7 +138,7 @@ unicode_val_T cp_to_unicode(int, unsigned char **, unsigned char *);
 unicode_val_T cp2u(int, unsigned char);
 unsigned char *cp2utf8(int, int);
 
-unsigned char *u2cp_(unicode_val_T, int, enum nbsp_mode);
+const unsigned char *u2cp_(unicode_val_T, int, enum nbsp_mode);
 #define u2cp(u, to) u2cp_(u, to, NBSP_MODE_HACK)
 #define u2cp_no_nbsp(u, to) u2cp_(u, to, NBSP_MODE_ASCII)
 
diff --git a/src/terminal/event.c b/src/terminal/event.c
index 49913aaba..6d5dc40c7 100644
--- a/src/terminal/event.c
+++ b/src/terminal/event.c
@@ -143,7 +143,7 @@ term_send_ucs(struct terminal *term, unicode_val_T u,
 	term_send_event(term, &ev);
 #else  /* !CONFIG_UTF8 */
 	struct term_event ev;
-	unsigned char *recoded;
+	const unsigned char *recoded;
 
 	set_kbd_term_event(&ev, KBD_UNDEF, modifier);
 	recoded = u2cp_no_nbsp(u, get_opt_codepage_tree(term->spec, "charset"));
diff --git a/src/viewer/text/form.c b/src/viewer/text/form.c
index 83d904f4f..483931f68 100644
--- a/src/viewer/text/form.c
+++ b/src/viewer/text/form.c
@@ -1355,6 +1355,7 @@ field_op(struct session *ses, struct document_view *doc_view,
 	struct form_state *fs;
 	enum edit_action action_id;
 	unsigned char *text;
+	const unsigned char *ctext;
 	int length;
 	enum frame_event_status status = FRAME_EVENT_REFRESH;
 #ifdef CONFIG_UTF8
@@ -1748,19 +1749,19 @@ field_op(struct session *ses, struct document_view *doc_view,
 			if (ses->tab->term->utf8) {
 				/* fs->value is in UTF-8 regardless of
 				 * the charset of the terminal.  */
-				text = encode_utf8(get_kbd_key(ev));
+				ctext = encode_utf8(get_kbd_key(ev));
 			} else {
 				/* fs->value is in the charset of the
 				 * terminal.  */
 				int cp = get_opt_codepage_tree(ses->tab->term->spec,
 							       "charset");
 
-				text = u2cp_no_nbsp(get_kbd_key(ev), cp);
+				ctext = u2cp_no_nbsp(get_kbd_key(ev), cp);
 			}
-			length = strlen(text);
+			length = strlen(ctext);
 
 			if (strlen(fs->value) + length > fc->maxlength
-			    || !insert_in_string(&fs->value, fs->state, text, length)) {
+			    || !insert_in_string(&fs->value, fs->state, ctext, length)) {
 				status = FRAME_EVENT_OK;
 				break;
 			}

From 251dcb7f9f7f43b463d765f01c2451965dd5674a Mon Sep 17 00:00:00 2001
From: Kalle Olavi Niemitalo <kon@iki.fi>
Date: Tue, 2 Jan 2007 21:22:51 +0200
Subject: [PATCH 16/21] Make errfile point to const.

---
 src/util/error.c | 2 +-
 src/util/error.h | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/src/util/error.c b/src/util/error.c
index e2d5408e8..34e4c88f1 100644
--- a/src/util/error.c
+++ b/src/util/error.c
@@ -52,7 +52,7 @@ er(int bell, int shall_sleep, unsigned char *fmt, va_list params)
 }
 
 int errline;
-unsigned char *errfile;
+const unsigned char *errfile;
 
 void
 elinks_debug(unsigned char *fmt, ...)
diff --git a/src/util/error.h b/src/util/error.h
index 4b56b51d9..a97c921b8 100644
--- a/src/util/error.h
+++ b/src/util/error.h
@@ -11,7 +11,7 @@
 /* This errfile thing is needed, as we don't have var-arg macros in standart,
  * only as gcc extension :(. */
 extern int errline;
-extern unsigned char *errfile;
+extern const unsigned char *errfile;
 
 /* @DBG(format_string) is used for printing of debugging information. It
  * should not be used anywhere in the official codebase (although it is often

From 882d179fc83b5e9073f4eb4b57a5a4dc4138de94 Mon Sep 17 00:00:00 2001
From: Kalle Olavi Niemitalo <kon@iki.fi>
Date: Tue, 2 Jan 2007 21:25:20 +0200
Subject: [PATCH 17/21] Make many string parameters const in the memory leak
 detector.

---
 src/util/memdebug.c | 30 +++++++++++++++---------------
 src/util/memdebug.h | 10 +++++-----
 2 files changed, 20 insertions(+), 20 deletions(-)

diff --git a/src/util/memdebug.c b/src/util/memdebug.c
index 26c653807..612a91565 100644
--- a/src/util/memdebug.c
+++ b/src/util/memdebug.c
@@ -114,7 +114,7 @@ struct alloc_header {
 #endif
 	int size;
 	int line;
-	unsigned char *file;
+	const unsigned char *file;
 	unsigned char *comment;
 
 #ifdef CHECK_XFLOWS
@@ -167,8 +167,8 @@ INIT_LIST_HEAD(memory_list);
 
 #ifdef LOG_MEMORY_ALLOC
 static void
-dump_short_info(struct alloc_header *ah, unsigned char *file, int line,
-		unsigned char *type)
+dump_short_info(struct alloc_header *ah, const unsigned char *file, int line,
+		const unsigned char *type)
 {
 	fprintf(stderr, "%p", PTR_AH2BASE(ah)), fflush(stderr);
 	fprintf(stderr, ":%d", ah->size), fflush(stderr);
@@ -184,8 +184,8 @@ dump_short_info(struct alloc_header *ah, unsigned char *file, int line,
 #endif
 
 static void
-dump_info(struct alloc_header *ah, unsigned char *info,
-	  unsigned char *file, int line, unsigned char *type)
+dump_info(struct alloc_header *ah, const unsigned char *info,
+	  const unsigned char *file, int line, const unsigned char *type)
 {
 	fprintf(stderr, "%p", PTR_AH2BASE(ah)); fflush(stderr);
 	/* In some extreme cases, we may core here, as 'ah' can no longer point
@@ -213,8 +213,8 @@ dump_info(struct alloc_header *ah, unsigned char *info,
 
 #ifdef CHECK_AH_SANITY
 static inline int
-bad_ah_sanity(struct alloc_header *ah, unsigned char *info,
-	      unsigned char *file, int line)
+bad_ah_sanity(struct alloc_header *ah, const unsigned char *info,
+	      const unsigned char *file, int line)
 {
 	if (!ah) return 1;
 	if (ah->magic != AH_SANITY_MAGIC) {
@@ -228,8 +228,8 @@ bad_ah_sanity(struct alloc_header *ah, unsigned char *info,
 
 #ifdef CHECK_XFLOWS
 static inline int
-bad_xflow_magic(struct alloc_header *ah, unsigned char *info,
-		unsigned char *file, int line)
+bad_xflow_magic(struct alloc_header *ah, const unsigned char *info,
+		const unsigned char *file, int line)
 {
 	if (!ah) return 1;
 
@@ -282,7 +282,7 @@ check_memory_leaks(void)
 static int alloc_try = 0;
 
 static int
-patience(unsigned char *file, int line, unsigned char *of)
+patience(const unsigned char *file, int line, const unsigned char *of)
 {
 	errfile = file;
 	errline = line;
@@ -310,7 +310,7 @@ patience(unsigned char *file, int line, unsigned char *of)
 }
 
 void *
-debug_mem_alloc(unsigned char *file, int line, size_t size)
+debug_mem_alloc(const unsigned char *file, int line, size_t size)
 {
 	struct alloc_header *ah;
 	size_t true_size;
@@ -354,7 +354,7 @@ debug_mem_alloc(unsigned char *file, int line, size_t size)
 }
 
 void *
-debug_mem_calloc(unsigned char *file, int line, size_t eltcount, size_t eltsize)
+debug_mem_calloc(const unsigned char *file, int line, size_t eltcount, size_t eltsize)
 {
 	struct alloc_header *ah;
 	size_t size = eltcount * eltsize;
@@ -405,7 +405,7 @@ debug_mem_calloc(unsigned char *file, int line, size_t eltcount, size_t eltsize)
 }
 
 void
-debug_mem_free(unsigned char *file, int line, void *ptr)
+debug_mem_free(const unsigned char *file, int line, void *ptr)
 {
 	struct alloc_header *ah;
 	int ok = 1;
@@ -485,7 +485,7 @@ debug_mem_free(unsigned char *file, int line, void *ptr)
 }
 
 void *
-debug_mem_realloc(unsigned char *file, int line, void *ptr, size_t size)
+debug_mem_realloc(const unsigned char *file, int line, void *ptr, size_t size)
 {
 	struct alloc_header *ah, *ah2;
 	size_t true_size;
@@ -558,7 +558,7 @@ debug_mem_realloc(unsigned char *file, int line, void *ptr, size_t size)
 }
 
 void
-set_mem_comment(void *ptr, unsigned char *str, int len)
+set_mem_comment(void *ptr, const unsigned char *str, int len)
 {
 	struct alloc_header *ah;
 
diff --git a/src/util/memdebug.h b/src/util/memdebug.h
index 3917be4fc..bcccd41a5 100644
--- a/src/util/memdebug.h
+++ b/src/util/memdebug.h
@@ -12,11 +12,11 @@ struct mem_stats {
 
 extern struct mem_stats mem_stats;
 
-void *debug_mem_alloc(unsigned char *, int, size_t);
-void *debug_mem_calloc(unsigned char *, int, size_t, size_t);
-void debug_mem_free(unsigned char *, int, void *);
-void *debug_mem_realloc(unsigned char *, int, void *, size_t);
-void set_mem_comment(void *, unsigned char *, int);
+void *debug_mem_alloc(const unsigned char *, int, size_t);
+void *debug_mem_calloc(const unsigned char *, int, size_t, size_t);
+void debug_mem_free(const unsigned char *, int, void *);
+void *debug_mem_realloc(const unsigned char *, int, void *, size_t);
+void set_mem_comment(void *, const unsigned char *, int);
 
 void check_memory_leaks(void);
 

From 176bbe83b67bf01cf3f71e3b4878e651c1d365ca Mon Sep 17 00:00:00 2001
From: Kalle Olavi Niemitalo <kon@iki.fi>
Date: Tue, 2 Jan 2007 21:26:55 +0200
Subject: [PATCH 18/21] Make input data and source file names const in memacpy
 and stracpy.

---
 src/util/string.c | 8 ++++----
 src/util/string.h | 8 ++++----
 2 files changed, 8 insertions(+), 8 deletions(-)

diff --git a/src/util/string.c b/src/util/string.c
index ab486ff46..d6a213463 100644
--- a/src/util/string.c
+++ b/src/util/string.c
@@ -40,7 +40,7 @@
 #ifdef DEBUG_MEMLEAK
 
 unsigned char *
-debug_memacpy(unsigned char *f, int l, unsigned char *src, int len)
+debug_memacpy(const unsigned char *f, int l, const unsigned char *src, int len)
 {
 	unsigned char *m;
 
@@ -57,7 +57,7 @@ debug_memacpy(unsigned char *f, int l, unsigned char *src, int len)
 }
 
 unsigned char *
-debug_stracpy(unsigned char *f, int l, unsigned char *src)
+debug_stracpy(const unsigned char *f, int l, const unsigned char *src)
 {
 	string_assert(f, l, src, "stracpy");
 	if_assert_failed return NULL;
@@ -68,7 +68,7 @@ debug_stracpy(unsigned char *f, int l, unsigned char *src)
 #else /* DEBUG_MEMLEAK */
 
 unsigned char *
-memacpy(unsigned char *src, int len)
+memacpy(const unsigned char *src, int len)
 {
 	unsigned char *m;
 
@@ -85,7 +85,7 @@ memacpy(unsigned char *src, int len)
 }
 
 unsigned char *
-stracpy(unsigned char *src)
+stracpy(const unsigned char *src)
 {
 	assertm(src, "[stracpy]");
 	if_assert_failed return NULL;
diff --git a/src/util/string.h b/src/util/string.h
index 215f2ba92..d3a0320cf 100644
--- a/src/util/string.h
+++ b/src/util/string.h
@@ -25,17 +25,17 @@
 /* Allocates NUL terminated string with @len bytes from @src.
  * If @src == NULL or @len < 0 only one byte is allocated and set it to 0. */
 /* Returns the string or NULL on allocation failure. */
-unsigned char *memacpy(unsigned char *src, int len);
+unsigned char *memacpy(const unsigned char *src, int len);
 
 /* Allocated NUL terminated string with the content of @src. */
-unsigned char *stracpy(unsigned char *src);
+unsigned char *stracpy(const unsigned char *src);
 
 #else /* DEBUG_MEMLEAK */
 
-unsigned char *debug_memacpy(unsigned char *, int, unsigned char *, int);
+unsigned char *debug_memacpy(const unsigned char *, int, const unsigned char *, int);
 #define memacpy(s, l) debug_memacpy(__FILE__, __LINE__, s, l)
 
-unsigned char *debug_stracpy(unsigned char *, int, unsigned char *);
+unsigned char *debug_stracpy(const unsigned char *, int, const unsigned char *);
 #define stracpy(s) debug_stracpy(__FILE__, __LINE__, s)
 
 #endif /* DEBUG_MEMLEAK */

From 62d321fb3104f70b918cb77076db63ec2a6f3889 Mon Sep 17 00:00:00 2001
From: Kalle Olavi Niemitalo <kon@iki.fi>
Date: Tue, 2 Jan 2007 21:36:03 +0200
Subject: [PATCH 19/21] Make add_utf8 accept a pointer to const.

---
 src/intl/charsets.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/src/intl/charsets.c b/src/intl/charsets.c
index c8f350d9d..cc2b7323a 100644
--- a/src/intl/charsets.c
+++ b/src/intl/charsets.c
@@ -772,7 +772,7 @@ cp_to_unicode(int codepage, unsigned char **string, unsigned char *end)
 
 
 static void
-add_utf8(struct conv_table *ct, unicode_val_T u, unsigned char *str)
+add_utf8(struct conv_table *ct, unicode_val_T u, const unsigned char *str)
 {
 	unsigned char *p = encode_utf8(u);
 

From 1668d78998660ff1461e3558a186fa0c25c6db10 Mon Sep 17 00:00:00 2001
From: Kalle Olavi Niemitalo <kon@iki.fi>
Date: Tue, 2 Jan 2007 21:39:34 +0200
Subject: [PATCH 20/21] Make cp2utf8 return a pointer to const.

---
 src/intl/charsets.c | 2 +-
 src/intl/charsets.h | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/src/intl/charsets.c b/src/intl/charsets.c
index cc2b7323a..e1eb11a89 100644
--- a/src/intl/charsets.c
+++ b/src/intl/charsets.c
@@ -741,7 +741,7 @@ cp2u(int from, unsigned char c)
 }
 
 /* This slow and ugly code is used by the terminal utf_8_io */
-unsigned char *
+const unsigned char *
 cp2utf8(int from, int c)
 {
 	from &= ~SYSTEM_CHARSET_FLAG;
diff --git a/src/intl/charsets.h b/src/intl/charsets.h
index bee9d14e5..7f95e3e84 100644
--- a/src/intl/charsets.h
+++ b/src/intl/charsets.h
@@ -136,7 +136,7 @@ unicode_val_T cp_to_unicode(int, unsigned char **, unsigned char *);
 #endif /* CONFIG_UTF8 */
 
 unicode_val_T cp2u(int, unsigned char);
-unsigned char *cp2utf8(int, int);
+const unsigned char *cp2utf8(int, int);
 
 const unsigned char *u2cp_(unicode_val_T, int, enum nbsp_mode);
 #define u2cp(u, to) u2cp_(u, to, NBSP_MODE_HACK)

From 455ea77eadbf20b0e34fb6f84ed1d85bab15a06a Mon Sep 17 00:00:00 2001
From: Kalle Olavi Niemitalo <kon@iki.fi>
Date: Tue, 2 Jan 2007 21:40:14 +0200
Subject: [PATCH 21/21] Make strings[] and no_str[] const.

---
 src/intl/charsets.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/src/intl/charsets.c b/src/intl/charsets.c
index e1eb11a89..560443137 100644
--- a/src/intl/charsets.c
+++ b/src/intl/charsets.c
@@ -70,7 +70,7 @@ struct codepage_desc {
 #include "intl/entity.inc"
 
 
-static char strings[256][2] = {
+static const char strings[256][2] = {
 	"\000", "\001", "\002", "\003", "\004", "\005", "\006", "\007",
 	"\010", "\011", "\012", "\013", "\014", "\015", "\016", "\017",
 	"\020", "\021", "\022", "\023", "\024", "\025", "\026", "\033",
@@ -122,7 +122,7 @@ free_translation_table(struct conv_table *p)
  * named array rather than a pointer so that it won't share storage
  * with any other string literal that happens to have the same
  * characters.  */
-static unsigned char no_str[] = "*";
+static const unsigned char no_str[] = "*";
 
 static void
 new_translation_table(struct conv_table *p)