public inbox for lvm2-cvs@sourceware.org
help / color / mirror / Atom feed
* LVM2 ./WHATS_NEW lib/misc/lvm-string.c
@ 2010-09-28  1:29 agk
  0 siblings, 0 replies; 5+ messages in thread
From: agk @ 2010-09-28  1:29 UTC (permalink / raw)
  To: lvm-devel, lvm2-cvs

CVSROOT:	/cvs/lvm2
Module name:	LVM2
Changes by:	agk@sourceware.org	2010-09-28 01:29:07

Modified files:
	.              : WHATS_NEW 
	lib/misc       : lvm-string.c 

Log message:
	Speed up unquoting of quoted double quotes and backslashes.

Patches:
http://sourceware.org/cgi-bin/cvsweb.cgi/LVM2/WHATS_NEW.diff?cvsroot=lvm2&r1=1.1737&r2=1.1738
http://sourceware.org/cgi-bin/cvsweb.cgi/LVM2/lib/misc/lvm-string.c.diff?cvsroot=lvm2&r1=1.22&r2=1.23

--- LVM2/WHATS_NEW	2010/09/27 19:09:34	1.1737
+++ LVM2/WHATS_NEW	2010/09/28 01:29:06	1.1738
@@ -1,5 +1,6 @@
 Version 2.02.75 - 
 =====================================
+  Speed up unquoting of quoted double quotes and backslashes.
   Speed up CRC32 calculations by using a larger lookup table.
 
 Version 2.02.74 - 24th September 2010
--- LVM2/lib/misc/lvm-string.c	2010/09/23 12:02:34	1.22
+++ LVM2/lib/misc/lvm-string.c	2010/09/28 01:29:07	1.23
@@ -108,33 +108,64 @@
 	}
 }
 
+static void _unquote_one_character(char *src, const char orig_char,
+				   const char quote_char)
+{
+	char *out;
+	char s, n;
+
+	/* Optimise for the common case where no changes are needed. */
+	while ((s = *src++)) {
+		if (s == quote_char &&
+		    ((n = *src) == orig_char || n == quote_char)) {
+			out = src++;
+			*(out - 1) = n;
+
+			while ((s = *src++)) {
+				if (s == quote_char &&
+				    ((n = *src) == orig_char || n == quote_char)) {
+					s = n;
+					src++;
+				}
+				*out = s;
+				out++;
+			}
+
+			*out = '\0';
+			return;
+		}
+	}
+}
+
 /*
  * Unquote each character given in orig_char array and unquote quote_char
- * as well. The array ends up with '\0' character. Also save the first
- * occurence of each character from orig_char that was found unquoted in
- * arr_substr_first_unquoted array. This way we can process several
- * characters in one go.
+ * as well. Also save the first occurrence of each character from orig_char
+ * that was found unquoted in arr_substr_first_unquoted array. This way we can
+ * process several characters in one go.
  */
-static void _unquote_characters(char *src, const int orig_chars[],
-				const int quote_char,
+static void _unquote_characters(char *src, const char *orig_chars,
+				const int num_orig_chars, 
+				const char quote_char,
 				char *arr_substr_first_unquoted[])
 {
 	char *out = src;
-	int c;
-	int i;
+	char c, s, n;
+	unsigned i;
 
-	while (*src) {
-		for (i = 0; (c = orig_chars[i]); i++) {
-			if (*src == quote_char &&
-			    (*(src + 1) == c || *(src + 1) == quote_char)) {
+	while ((s = *src++)) {
+		for (i = 0; i < num_orig_chars; i++) {
+			c = orig_chars[i];
+			if (s == quote_char &&
+			    ((n = *src) == c || n == quote_char)) {
+				s = n;
 				src++;
 				break;
 			}
-			else if (arr_substr_first_unquoted && (*src == c) &&
-				 !arr_substr_first_unquoted[i])
+			if (arr_substr_first_unquoted && (s == c) &&
+			    !arr_substr_first_unquoted[i])
 				arr_substr_first_unquoted[i] = out;
-		}
-		*out++ = *src++;
+		};
+		*out++ = s;
 	}
 
 	*out = '\0';
@@ -229,9 +260,7 @@
  */
 void unescape_double_quotes(char *src)
 {
-	const int orig_chars[] = {'\"', '\0'};
-
-	_unquote_characters(src, orig_chars, '\\', NULL);
+	_unquote_one_character(src, '\"', '\\');
 }
 
 /*
@@ -244,10 +273,10 @@
 				  char **substr_first_unquoted_colon,
 				  char **substr_first_unquoted_at_sign)
 {
-	const int orig_chars[] = {':', '@', '\0'};
+	const char *orig_chars = ":@";
 	char *arr_substr_first_unquoted[] = {NULL, NULL, NULL};
 
-	_unquote_characters(src, orig_chars, '\\', arr_substr_first_unquoted);
+	_unquote_characters(src, orig_chars, 2, '\\', arr_substr_first_unquoted);
 
 	if (substr_first_unquoted_colon)
 		*substr_first_unquoted_colon = arr_substr_first_unquoted[0];


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

* LVM2 ./WHATS_NEW lib/misc/lvm-string.c
@ 2011-03-13 23:18 zkabelac
  0 siblings, 0 replies; 5+ messages in thread
From: zkabelac @ 2011-03-13 23:18 UTC (permalink / raw)
  To: lvm-devel, lvm2-cvs

CVSROOT:	/cvs/lvm2
Module name:	LVM2
Changes by:	zkabelac@sourceware.org	2011-03-13 23:18:30

Modified files:
	.              : WHATS_NEW 
	lib/misc       : lvm-string.c 

Log message:
	Revert this commit
	
	This buffer allocation must have been problem somewhere else.
	(as sizeof() already has the 'extra' '\0' included).
	For now reverting this commit.

Patches:
http://sourceware.org/cgi-bin/cvsweb.cgi/LVM2/WHATS_NEW.diff?cvsroot=lvm2&r1=1.1954&r2=1.1955
http://sourceware.org/cgi-bin/cvsweb.cgi/LVM2/lib/misc/lvm-string.c.diff?cvsroot=lvm2&r1=1.25&r2=1.26

--- LVM2/WHATS_NEW	2011/03/13 23:05:48	1.1954
+++ LVM2/WHATS_NEW	2011/03/13 23:18:30	1.1955
@@ -1,7 +1,6 @@
 Version 2.02.85 - 
 ===================================
   Fix allocation of system_id buffer in volume_group structure.
-  Fix buffer allocation in build_dm_uuid().
   Fix readlink usage inside get_primary_dev().
   Use format instance mempool where possible and adequate.
   Call destroy_instance for any PVs found in VG structure during vg_free call.
--- LVM2/lib/misc/lvm-string.c	2011/03/13 22:57:51	1.25
+++ LVM2/lib/misc/lvm-string.c	2011/03/13 23:18:30	1.26
@@ -229,7 +229,7 @@
 	if (!layer)
 		layer = "";
 
-	len = sizeof(UUID_PREFIX) + strlen(lvid) + strlen(layer) + 1 + 1;
+	len = sizeof(UUID_PREFIX) + strlen(lvid) + strlen(layer) + 1;
 
 	if (!(dmuuid = dm_pool_alloc(mem, len))) {
 		log_error("build_dm_name: Allocation failed for %" PRIsize_t


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

* LVM2 ./WHATS_NEW lib/misc/lvm-string.c
@ 2011-03-13 22:57 zkabelac
  0 siblings, 0 replies; 5+ messages in thread
From: zkabelac @ 2011-03-13 22:57 UTC (permalink / raw)
  To: lvm-devel, lvm2-cvs

CVSROOT:	/cvs/lvm2
Module name:	LVM2
Changes by:	zkabelac@sourceware.org	2011-03-13 22:57:51

Modified files:
	.              : WHATS_NEW 
	lib/misc       : lvm-string.c 

Log message:
	Fix buffer allocation size for uuid string
	
	We have 3 components and traling '\0' so allocate proper room for all of them.
	Problem was nicely hidden by allocation from pool and allocation aligment
	offset - so to trigger real problem with this one is actually hard.

Patches:
http://sourceware.org/cgi-bin/cvsweb.cgi/LVM2/WHATS_NEW.diff?cvsroot=lvm2&r1=1.1952&r2=1.1953
http://sourceware.org/cgi-bin/cvsweb.cgi/LVM2/lib/misc/lvm-string.c.diff?cvsroot=lvm2&r1=1.24&r2=1.25

--- LVM2/WHATS_NEW	2011/03/13 22:52:16	1.1952
+++ LVM2/WHATS_NEW	2011/03/13 22:57:51	1.1953
@@ -1,5 +1,6 @@
 Version 2.02.85 - 
 ===================================
+  Fix buffer allocation in build_dm_uuid().
   Fix readlink usage inside get_primary_dev().
   Use format instance mempool where possible and adequate.
   Call destroy_instance for any PVs found in VG structure during vg_free call.
--- LVM2/lib/misc/lvm-string.c	2010/11/17 10:19:30	1.24
+++ LVM2/lib/misc/lvm-string.c	2011/03/13 22:57:51	1.25
@@ -229,7 +229,7 @@
 	if (!layer)
 		layer = "";
 
-	len = sizeof(UUID_PREFIX) + strlen(lvid) + strlen(layer) + 1;
+	len = sizeof(UUID_PREFIX) + strlen(lvid) + strlen(layer) + 1 + 1;
 
 	if (!(dmuuid = dm_pool_alloc(mem, len))) {
 		log_error("build_dm_name: Allocation failed for %" PRIsize_t


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

* LVM2 ./WHATS_NEW lib/misc/lvm-string.c
@ 2010-09-20 14:25 prajnoha
  0 siblings, 0 replies; 5+ messages in thread
From: prajnoha @ 2010-09-20 14:25 UTC (permalink / raw)
  To: lvm-devel, lvm2-cvs

CVSROOT:	/cvs/lvm2
Module name:	LVM2
Changes by:	prajnoha@sourceware.org	2010-09-20 14:25:27

Modified files:
	.              : WHATS_NEW 
	lib/misc       : lvm-string.c 

Log message:
	Revert to old glibc behaviour for vsnprintf used in emit_to_buffer function.
	
	Revert to old glibc behaviour for vsnprintf used in emit_to_buffer fn.
	Otherwise, the check that follows would be wrong for new glibc versions.
	This caused the rh bug #633033 to be undetected and pass throught the check,
	corrupting the metadata!

Patches:
http://sourceware.org/cgi-bin/cvsweb.cgi/LVM2/WHATS_NEW.diff?cvsroot=lvm2&r1=1.1730&r2=1.1731
http://sourceware.org/cgi-bin/cvsweb.cgi/LVM2/lib/misc/lvm-string.c.diff?cvsroot=lvm2&r1=1.20&r2=1.21

--- LVM2/WHATS_NEW	2010/09/20 14:23:20	1.1730
+++ LVM2/WHATS_NEW	2010/09/20 14:25:27	1.1731
@@ -1,5 +1,6 @@
 Version 2.02.74 - 
 ==================================
+  Revert to old glibc behaviour for vsnprintf used in emit_to_buffer function.
   Use dynamic allocation for metadata's tag buffer (removes 4096 char. limit).
   Add random suffix to archive file names to prevent races when being created.
   Reinitialize archive and backup handling on toolcontext refresh.
--- LVM2/lib/misc/lvm-string.c	2010/04/23 14:16:33	1.20
+++ LVM2/lib/misc/lvm-string.c	2010/09/20 14:25:27	1.21
@@ -27,6 +27,14 @@
 	n = vsnprintf(*buffer, *size, fmt, ap);
 	va_end(ap);
 
+	/*
+	 * Revert to old glibc behaviour (version <= 2.0.6) where snprintf
+	 * returned -1 if buffer was too small. From glibc 2.1 it returns number
+	 * of chars that would have been written had there been room.
+	 */
+	if (n < 0 || ((unsigned) n + 1 > *size))
+		n = -1;
+
 	if (n < 0 || ((size_t)n == *size))
 		return 0;
 


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

* LVM2 ./WHATS_NEW lib/misc/lvm-string.c
@ 2004-10-11 15:59 agk
  0 siblings, 0 replies; 5+ messages in thread
From: agk @ 2004-10-11 15:59 UTC (permalink / raw)
  To: lvm2-cvs

CVSROOT:	/cvs/lvm2
Module name:	LVM2
Changes by:	agk@sourceware.org	2004-10-11 15:59:23

Modified files:
	.              : WHATS_NEW 
	lib/misc       : lvm-string.c 

Log message:
	Fix size of dm_name string.

Patches:
http://sources.redhat.com/cgi-bin/cvsweb.cgi/LVM2/WHATS_NEW.diff?cvsroot=lvm2&r1=1.102&r2=1.103
http://sources.redhat.com/cgi-bin/cvsweb.cgi/LVM2/lib/misc/lvm-string.c.diff?cvsroot=lvm2&r1=1.5&r2=1.6


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

end of thread, other threads:[~2011-03-13 23:18 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2010-09-28  1:29 LVM2 ./WHATS_NEW lib/misc/lvm-string.c agk
  -- strict thread matches above, loose matches on Subject: below --
2011-03-13 23:18 zkabelac
2011-03-13 22:57 zkabelac
2010-09-20 14:25 prajnoha
2004-10-11 15:59 agk

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).