summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorPaul Eggert <eggert@cs.ucla.edu>2011-06-22 09:01:00 -0700
committerPaul Eggert <eggert@cs.ucla.edu>2011-06-22 09:01:00 -0700
commit510005210ac9f4d813c4a2cc99b2c3c11e57c055 (patch)
tree85b8b7bd35e451c71f9f58f2de3ae3ae16c0b25f /src
parentb79e8648b908c6600b99c20d4782e6413d6907ef (diff)
parentddb7ffeeb8ace6501eb453f50f0f9f6852eda21f (diff)
downloademacs-510005210ac9f4d813c4a2cc99b2c3c11e57c055.tar.gz
Merge from trunk.
Diffstat (limited to 'src')
-rw-r--r--src/ChangeLog27
-rw-r--r--src/composite.c1
-rw-r--r--src/deps.mk4
-rw-r--r--src/fns.c139
-rw-r--r--src/image.c1
-rw-r--r--src/intervals.c17
-rw-r--r--src/makefile.w32-in2
7 files changed, 125 insertions, 66 deletions
diff --git a/src/ChangeLog b/src/ChangeLog
index 4aca4d0f5d6..5922c6800bb 100644
--- a/src/ChangeLog
+++ b/src/ChangeLog
@@ -19,8 +19,6 @@
(x_allocate_bitmap_record): Check for size overflow.
* dispextern.h, lisp.h: Adjust to API changes elsewhere.
-2011-06-21 Paul Eggert <eggert@cs.ucla.edu>
-
Use ptrdiff_t, not int, for overlay counts.
* buffer.h (overlays_at, sort_overlays, GET_OVERLAYS_AT):
* editfns.c (overlays_around, get_pos_property):
@@ -199,6 +197,31 @@
(record_overlay_string): Check for size-calculation overflow.
(init_buffer_once): Check at compile-time, not run-time.
+2011-06-22 Jim Meyering <meyering@redhat.com>
+
+ don't leak an XBM-image-sized buffer
+ * image.c (xbm_load): Free the image buffer after using it.
+
+2011-06-21 Paul Eggert <eggert@cs.ucla.edu>
+
+ Port to Sun C.
+ * composite.c (find_automatic_composition): Omit needless 'return 0;'
+ that Sun C diagnosed.
+ * fns.c (secure_hash): Fix pointer signedness issue.
+ * intervals.c (static_offset_intervals): New function.
+ (offset_intervals): Use it.
+
+2011-06-21 Leo Liu <sdl.web@gmail.com>
+
+ * deps.mk (fns.o):
+ * makefile.w32-in ($(BLD)/fns.$(O)): Include sha256.h and
+ sha512.h.
+
+ * fns.c (secure_hash): Rename from crypto_hash_function and change
+ the first arg to accept symbols.
+ (Fsecure_hash): New primtive.
+ (syms_of_fns): New symbols.
+
2011-06-20 Deniz Dogan <deniz@dogan.se>
* process.c (Fset_process_buffer): Clarify return value in
diff --git a/src/composite.c b/src/composite.c
index f494f454a9c..796c5a58de6 100644
--- a/src/composite.c
+++ b/src/composite.c
@@ -1677,7 +1677,6 @@ find_automatic_composition (EMACS_INT pos, EMACS_INT limit,
}
BACKWARD_CHAR (cur, stop);
}
- return 0;
}
/* Return the adjusted point provided that point is moved from LAST_PT
diff --git a/src/deps.mk b/src/deps.mk
index 6c677f0e6c6..080144ae1e5 100644
--- a/src/deps.mk
+++ b/src/deps.mk
@@ -284,8 +284,8 @@ eval.o: eval.c commands.h keyboard.h blockinput.h atimer.h systime.h frame.h \
floatfns.o: floatfns.c syssignal.h lisp.h globals.h $(config_h)
fns.o: fns.c commands.h lisp.h $(config_h) frame.h buffer.h character.h \
keyboard.h keymap.h window.h $(INTERVALS_H) coding.h ../lib/md5.h \
- ../lib/sha1.h blockinput.h atimer.h systime.h xterm.h ../lib/unistd.h \
- globals.h
+ ../lib/sha1.h ../lib/sha256.h ../lib/sha512.h blockinput.h atimer.h \
+ systime.h xterm.h ../lib/unistd.h globals.h
print.o: print.c process.h frame.h window.h buffer.h keyboard.h character.h \
lisp.h globals.h $(config_h) termchar.h $(INTERVALS_H) msdos.h termhooks.h \
blockinput.h atimer.h systime.h font.h charset.h coding.h ccl.h \
diff --git a/src/fns.c b/src/fns.c
index da86d91b2b5..5bf274030a3 100644
--- a/src/fns.c
+++ b/src/fns.c
@@ -53,6 +53,8 @@ Lisp_Object Qcursor_in_echo_area;
static Lisp_Object Qwidget_type;
static Lisp_Object Qcodeset, Qdays, Qmonths, Qpaper;
+static Lisp_Object Qmd5, Qsha1, Qsha224, Qsha256, Qsha384, Qsha512;
+
static int internal_equal (Lisp_Object , Lisp_Object, int, int);
#ifndef HAVE_UNISTD_H
@@ -4544,21 +4546,18 @@ including negative integers. */)
/************************************************************************
- MD5 and SHA1
+ MD5, SHA-1, and SHA-2
************************************************************************/
#include "md5.h"
#include "sha1.h"
+#include "sha256.h"
+#include "sha512.h"
-/* Convert a possibly-signed character to an unsigned character. This is
- a bit safer than casting to unsigned char, since it catches some type
- errors that the cast doesn't. */
-static inline unsigned char to_uchar (char ch) { return ch; }
-
-/* TYPE: 0 for md5, 1 for sha1. */
+/* ALGORITHM is a symbol: md5, sha1, sha224 and so on. */
static Lisp_Object
-crypto_hash_function (int type, Lisp_Object object, Lisp_Object start, Lisp_Object end, Lisp_Object coding_system, Lisp_Object noerror, Lisp_Object binary)
+secure_hash (Lisp_Object algorithm, Lisp_Object object, Lisp_Object start, Lisp_Object end, Lisp_Object coding_system, Lisp_Object noerror, Lisp_Object binary)
{
int i;
EMACS_INT size;
@@ -4568,7 +4567,11 @@ crypto_hash_function (int type, Lisp_Object object, Lisp_Object start, Lisp_Obje
register EMACS_INT b, e;
register struct buffer *bp;
EMACS_INT temp;
- Lisp_Object res=Qnil;
+ int digest_size;
+ void *(*hash_func) (const char *, size_t, void *);
+ Lisp_Object digest;
+
+ CHECK_SYMBOL (algorithm);
if (STRINGP (object))
{
@@ -4739,47 +4742,61 @@ crypto_hash_function (int type, Lisp_Object object, Lisp_Object start, Lisp_Obje
object = code_convert_string (object, coding_system, Qnil, 1, 0, 0);
}
- switch (type)
+ if (EQ (algorithm, Qmd5))
{
- case 0: /* MD5 */
- {
- char digest[16];
- md5_buffer (SSDATA (object) + start_byte,
- SBYTES (object) - (size_byte - end_byte),
- digest);
+ digest_size = MD5_DIGEST_SIZE;
+ hash_func = md5_buffer;
+ }
+ else if (EQ (algorithm, Qsha1))
+ {
+ digest_size = SHA1_DIGEST_SIZE;
+ hash_func = sha1_buffer;
+ }
+ else if (EQ (algorithm, Qsha224))
+ {
+ digest_size = SHA224_DIGEST_SIZE;
+ hash_func = sha224_buffer;
+ }
+ else if (EQ (algorithm, Qsha256))
+ {
+ digest_size = SHA256_DIGEST_SIZE;
+ hash_func = sha256_buffer;
+ }
+ else if (EQ (algorithm, Qsha384))
+ {
+ digest_size = SHA384_DIGEST_SIZE;
+ hash_func = sha384_buffer;
+ }
+ else if (EQ (algorithm, Qsha512))
+ {
+ digest_size = SHA512_DIGEST_SIZE;
+ hash_func = sha512_buffer;
+ }
+ else
+ error ("Invalid algorithm arg: %s", SDATA (Fsymbol_name (algorithm)));
- if (NILP (binary))
- {
- char value[33];
- for (i = 0; i < 16; i++)
- sprintf (&value[2 * i], "%02x", to_uchar (digest[i]));
- res = make_string (value, 32);
- }
- else
- res = make_string (digest, 16);
- break;
- }
+ /* allocate 2 x digest_size so that it can be re-used to hold the
+ hexified value */
+ digest = make_uninit_string (digest_size * 2);
- case 1: /* SHA1 */
- {
- char digest[20];
- sha1_buffer (SSDATA (object) + start_byte,
- SBYTES (object) - (size_byte - end_byte),
- digest);
- if (NILP (binary))
- {
- char value[41];
- for (i = 0; i < 20; i++)
- sprintf (&value[2 * i], "%02x", to_uchar (digest[i]));
- res = make_string (value, 40);
- }
- else
- res = make_string (digest, 20);
- break;
- }
- }
+ hash_func (SSDATA (object) + start_byte,
+ SBYTES (object) - (size_byte - end_byte),
+ SSDATA (digest));
- return res;
+ if (NILP (binary))
+ {
+ unsigned char *p = SDATA (digest);
+ for (i = digest_size - 1; i >= 0; i--)
+ {
+ static char const hexdigit[16] = "0123456789abcdef";
+ int p_i = p[i];
+ p[2 * i] = hexdigit[p_i >> 4];
+ p[2 * i + 1] = hexdigit[p_i & 0xf];
+ }
+ return digest;
+ }
+ else
+ return make_unibyte_string (SSDATA (digest), digest_size);
}
DEFUN ("md5", Fmd5, Smd5, 1, 5, 0,
@@ -4811,25 +4828,31 @@ If NOERROR is non-nil, silently assume the `raw-text' coding if the
guesswork fails. Normally, an error is signaled in such case. */)
(Lisp_Object object, Lisp_Object start, Lisp_Object end, Lisp_Object coding_system, Lisp_Object noerror)
{
- return crypto_hash_function (0, object, start, end, coding_system, noerror, Qnil);
+ return secure_hash (Qmd5, object, start, end, coding_system, noerror, Qnil);
}
-DEFUN ("sha1", Fsha1, Ssha1, 1, 4, 0,
- doc: /* Return the SHA-1 (Secure Hash Algorithm) of an OBJECT.
-
-OBJECT is either a string or a buffer. Optional arguments START and
-END are character positions specifying which portion of OBJECT for
-computing the hash. If BINARY is non-nil, return a string in binary
-form. */)
- (Lisp_Object object, Lisp_Object start, Lisp_Object end, Lisp_Object binary)
+DEFUN ("secure-hash", Fsecure_hash, Ssecure_hash, 2, 5, 0,
+ doc: /* Return the secure hash of an OBJECT.
+ALGORITHM is a symbol: md5, sha1, sha224, sha256, sha384 or sha512.
+OBJECT is either a string or a buffer.
+Optional arguments START and END are character positions specifying
+which portion of OBJECT for computing the hash. If BINARY is non-nil,
+return a string in binary form. */)
+ (Lisp_Object algorithm, Lisp_Object object, Lisp_Object start, Lisp_Object end, Lisp_Object binary)
{
- return crypto_hash_function (1, object, start, end, Qnil, Qnil, binary);
+ return secure_hash (algorithm, object, start, end, Qnil, Qnil, binary);
}
-
void
syms_of_fns (void)
{
+ DEFSYM (Qmd5, "md5");
+ DEFSYM (Qsha1, "sha1");
+ DEFSYM (Qsha224, "sha224");
+ DEFSYM (Qsha256, "sha256");
+ DEFSYM (Qsha384, "sha384");
+ DEFSYM (Qsha512, "sha512");
+
/* Hash table stuff. */
Qhash_table_p = intern_c_string ("hash-table-p");
staticpro (&Qhash_table_p);
@@ -4998,7 +5021,7 @@ this variable. */);
defsubr (&Sbase64_encode_string);
defsubr (&Sbase64_decode_string);
defsubr (&Smd5);
- defsubr (&Ssha1);
+ defsubr (&Ssecure_hash);
defsubr (&Slocale_info);
}
diff --git a/src/image.c b/src/image.c
index 01cc95f7b38..a9785e5d00f 100644
--- a/src/image.c
+++ b/src/image.c
@@ -2833,6 +2833,7 @@ xbm_load (struct frame *f, struct image *img)
}
success_p = xbm_load_image (f, img, contents, contents + size);
+ xfree (contents);
}
else
{
diff --git a/src/intervals.c b/src/intervals.c
index f9e9c864e13..4de001f2ffc 100644
--- a/src/intervals.c
+++ b/src/intervals.c
@@ -1425,10 +1425,15 @@ adjust_intervals_for_deletion (struct buffer *buffer,
/* Make the adjustments necessary to the interval tree of BUFFER to
represent an addition or deletion of LENGTH characters starting
at position START. Addition or deletion is indicated by the sign
- of LENGTH. */
+ of LENGTH.
-inline void
-offset_intervals (struct buffer *buffer, EMACS_INT start, EMACS_INT length)
+ The two inline functions (one static) pacify Sun C 5.8, a pre-C99
+ compiler that does not allow calling a static function (here,
+ adjust_intervals_for_deletion) from a non-static inline function. */
+
+static inline void
+static_offset_intervals (struct buffer *buffer, EMACS_INT start,
+ EMACS_INT length)
{
if (NULL_INTERVAL_P (BUF_INTERVALS (buffer)) || length == 0)
return;
@@ -1441,6 +1446,12 @@ offset_intervals (struct buffer *buffer, EMACS_INT start, EMACS_INT length)
adjust_intervals_for_deletion (buffer, start, -length);
}
}
+
+inline void
+offset_intervals (struct buffer *buffer, EMACS_INT start, EMACS_INT length)
+{
+ static_offset_intervals (buffer, start, length);
+}
/* Merge interval I with its lexicographic successor. The resulting
interval is returned, and has the properties of the original
diff --git a/src/makefile.w32-in b/src/makefile.w32-in
index d4fafcfc047..173fc673955 100644
--- a/src/makefile.w32-in
+++ b/src/makefile.w32-in
@@ -867,6 +867,8 @@ $(BLD)/fns.$(O) : \
$(EMACS_ROOT)/nt/inc/sys/time.h \
$(EMACS_ROOT)/lib/md5.h \
$(EMACS_ROOT)/lib/sha1.h \
+ $(EMACS_ROOT)/lib/sha256.h \
+ $(EMACS_ROOT)/lib/sha512.h \
$(LISP_H) \
$(SRC)/atimer.h \
$(SRC)/blockinput.h \