mirror of
https://github.com/MidnightCommander/mc
synced 2025-02-26 12:14:47 +03:00
* view.c (hex_search): Release buffer after use.
This commit is contained in:
parent
0c08ee1fdd
commit
3b83dc732f
@ -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>
|
2001-07-09 Pavel Roskin <proski@gnu.org>
|
||||||
|
|
||||||
* view.c (hex_search): Reimplement parser using sscanf. Add
|
* view.c (hex_search): Reimplement parser using sscanf. Add
|
||||||
|
21
src/view.c
21
src/view.c
@ -1681,20 +1681,24 @@ hex_search (WView *view, char *text)
|
|||||||
{
|
{
|
||||||
char *buffer; /* Where we hold the information */
|
char *buffer; /* Where we hold the information */
|
||||||
long pos; /* Where did we found the string */
|
long pos; /* Where did we found the string */
|
||||||
int i = 0;
|
|
||||||
int block_len = 0;
|
int block_len = 0;
|
||||||
int parse_error = 0;
|
int parse_error = 0;
|
||||||
|
|
||||||
|
if (!*text) {
|
||||||
|
view->found_len = 0;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
/* buffer will never be longer that text */
|
/* buffer will never be longer that text */
|
||||||
buffer = g_new (char, strlen (text));
|
buffer = g_new (char, strlen (text));
|
||||||
|
|
||||||
/* First convert the string to a stream of bytes */
|
/* First convert the string to a stream of bytes */
|
||||||
while (text [i]) {
|
while (*text) {
|
||||||
int val;
|
int val;
|
||||||
int ptr;
|
int ptr;
|
||||||
|
|
||||||
/* %i matches octal, decimal, and hexadecimal numbers */
|
/* %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 */
|
/* Allow signed and unsigned char in the user input */
|
||||||
if (val < -128 || val > 255) {
|
if (val < -128 || val > 255) {
|
||||||
parse_error = 1;
|
parse_error = 1;
|
||||||
@ -1702,13 +1706,13 @@ hex_search (WView *view, char *text)
|
|||||||
}
|
}
|
||||||
|
|
||||||
buffer [block_len++] = (char) val;
|
buffer [block_len++] = (char) val;
|
||||||
i += ptr;
|
text += ptr;
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Try quoted string, strip quotes */
|
/* Try quoted string, strip quotes */
|
||||||
if (sscanf (text + i, "\"%[^\"]\"%n", buffer + block_len, &ptr) > 0) {
|
if (sscanf (text, "\"%[^\"]\"%n", buffer + block_len, &ptr) > 0) {
|
||||||
i += ptr;
|
text += ptr;
|
||||||
block_len += ptr - 2;
|
block_len += ptr - 2;
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
@ -1719,8 +1723,7 @@ hex_search (WView *view, char *text)
|
|||||||
|
|
||||||
/* No valid bytes in the user input */
|
/* No valid bytes in the user input */
|
||||||
if (block_len <= 0 || parse_error) {
|
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);
|
g_free (buffer);
|
||||||
view->found_len = 0;
|
view->found_len = 0;
|
||||||
return;
|
return;
|
||||||
@ -1729,6 +1732,8 @@ hex_search (WView *view, char *text)
|
|||||||
/* Then start the search */
|
/* Then start the search */
|
||||||
pos = block_search (view, buffer, block_len);
|
pos = block_search (view, buffer, block_len);
|
||||||
|
|
||||||
|
g_free (buffer);
|
||||||
|
|
||||||
if (pos == -1){
|
if (pos == -1){
|
||||||
message (0, _(" Search "), _(" Search string not found "));
|
message (0, _(" Search "), _(" Search string not found "));
|
||||||
view->found_len = 0;
|
view->found_len = 0;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user