* view.c (hex_search): Release buffer after use.

This commit is contained in:
Pavel Roskin 2001-07-10 17:42:25 +00:00
parent 0c08ee1fdd
commit 3b83dc732f
2 changed files with 17 additions and 8 deletions

View File

@ -1,3 +1,7 @@
2001-07-10 Andrew V. Samoilov <kai@cmail.ru>
* view.c (hex_search): Release buffer after use.
2001-07-09 Pavel Roskin <proski@gnu.org>
* view.c (hex_search): Reimplement parser using sscanf. Add

View File

@ -1681,20 +1681,24 @@ hex_search (WView *view, char *text)
{
char *buffer; /* Where we hold the information */
long pos; /* Where did we found the string */
int i = 0;
int block_len = 0;
int parse_error = 0;
if (!*text) {
view->found_len = 0;
return;
}
/* buffer will never be longer that text */
buffer = g_new (char, strlen (text));
/* First convert the string to a stream of bytes */
while (text [i]) {
while (*text) {
int val;
int ptr;
/* %i matches octal, decimal, and hexadecimal numbers */
if (sscanf (text + i, "%i%n", &val, &ptr) > 0) {
if (sscanf (text, "%i%n", &val, &ptr) > 0) {
/* Allow signed and unsigned char in the user input */
if (val < -128 || val > 255) {
parse_error = 1;
@ -1702,13 +1706,13 @@ hex_search (WView *view, char *text)
}
buffer [block_len++] = (char) val;
i += ptr;
text += ptr;
continue;
}
/* Try quoted string, strip quotes */
if (sscanf (text + i, "\"%[^\"]\"%n", buffer + block_len, &ptr) > 0) {
i += ptr;
if (sscanf (text, "\"%[^\"]\"%n", buffer + block_len, &ptr) > 0) {
text += ptr;
block_len += ptr - 2;
continue;
}
@ -1719,8 +1723,7 @@ hex_search (WView *view, char *text)
/* No valid bytes in the user input */
if (block_len <= 0 || parse_error) {
if (*text)
message (0, _(" Search "), _("Invalid hex search expression"));
message (0, _(" Search "), _("Invalid hex search expression"));
g_free (buffer);
view->found_len = 0;
return;
@ -1729,6 +1732,8 @@ hex_search (WView *view, char *text)
/* Then start the search */
pos = block_search (view, buffer, block_len);
g_free (buffer);
if (pos == -1){
message (0, _(" Search "), _(" Search string not found "));
view->found_len = 0;