summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorzherczeg <zherczeg@2f5784b3-3f2a-0410-8824-cb99058d5e15>2011-12-19 14:05:44 +0000
committerzherczeg <zherczeg@2f5784b3-3f2a-0410-8824-cb99058d5e15>2011-12-19 14:05:44 +0000
commitf50b9070857052a77bebf6b4957d3a783068635b (patch)
tree8e588c9d942d5ea6ff589b85280a67d9dfb58ea2
parent2576d4686e427f362d435c24606db9e5a76b6339 (diff)
downloadpcre-f50b9070857052a77bebf6b4957d3a783068635b.tar.gz
byte flip moved before disk write in pcretest and typo fixes
git-svn-id: svn://vcs.exim.org/pcre/code/branches/pcre16@811 2f5784b3-3f2a-0410-8824-cb99058d5e15
-rw-r--r--pcre_byte_order.c5
-rw-r--r--pcretest.c106
2 files changed, 66 insertions, 45 deletions
diff --git a/pcre_byte_order.c b/pcre_byte_order.c
index 286dd95..10373b8 100644
--- a/pcre_byte_order.c
+++ b/pcre_byte_order.c
@@ -84,7 +84,7 @@ return (value >> 8) | (value << 8);
*************************************************/
/* This function swaps the bytes of a compiled pattern usually
-loaeded form the disk. It also sets the tables pointer, which
+loaded form the disk. It also sets the tables pointer, which
is likely an invalid pointer after reload.
Arguments:
@@ -123,7 +123,7 @@ if (re->magic_number == MAGIC_NUMBER)
}
if (re->magic_number != REVERSED_MAGIC_NUMBER) return PCRE_ERROR_BADMAGIC;
-if ((swap_uint16(re->flags) & PCRE_MODE) == 0) return PCRE_ERROR_BADMODE;
+if ((swap_uint16(re->flags) & PCRE_MODE) == 0) return PCRE_ERROR_BADMODE;
re->magic_number = MAGIC_NUMBER;
re->size = swap_uint32(re->size);
@@ -137,6 +137,7 @@ re->name_table_offset = swap_uint16(re->name_table_offset);
re->name_entry_size = swap_uint16(re->name_entry_size);
re->name_count = swap_uint16(re->name_count);
re->ref_count = swap_uint16(re->ref_count);
+re->tables = tables;
if (extra_data != NULL && (re->flags & PCRE_EXTRA_STUDY_DATA) != 0)
{
diff --git a/pcretest.c b/pcretest.c
index 6bd66bc..618e704 100644
--- a/pcretest.c
+++ b/pcretest.c
@@ -201,6 +201,9 @@ use these in the definitions of generic macros. */
#define PCRE_FREE_STUDY8(extra) \
pcre_free_study(extra)
+#define PCRE_PATTERN_TO_HOST_BYTE_ORDER8(re, extra, tables) \
+ pcre_pattern_to_host_byte_order(re, extra, tables)
+
#endif /* SUPPORT_PCRE8 */
@@ -225,6 +228,9 @@ use these in the definitions of generic macros. */
#define PCRE_STUDY16(extra, re, options, error) \
extra = pcre16_study(re, options, error)
+#define PCRE_PATTERN_TO_HOST_BYTE_ORDER16(re, extra, tables) \
+ pcre16_pattern_to_host_byte_order(re, extra, tables)
+
#endif /* SUPPORT_PCRE16 */
@@ -271,6 +277,12 @@ use these in the definitions of generic macros. */
else \
PCRE_STUDY8(extra, re, options, error)
+#define PCRE_PATTERN_TO_HOST_BYTE_ORDER(re, extra, tables) \
+ if (use_pcre16) \
+ PCRE_PATTERN_TO_HOST_BYTE_ORDER16(re, extra, tables); \
+ else \
+ PCRE_PATTERN_TO_HOST_BYTE_ORDER8(re, extra, tables)
+
/* ----- Only 8-bit mode is supported ----- */
#elif defined SUPPORT_PCRE8
@@ -280,6 +292,7 @@ use these in the definitions of generic macros. */
#define PCRE_EXEC PCRE_EXEC8
#define PCRE_FREE_STUDY PCRE_FREE_STUDY8
#define PCRE_STUDY PCRE_STUDY8
+#define PCRE_PATTERN_TO_HOST_BYTE_ORDER PCRE_PATTERN_TO_HOST_BYTE_ORDER8
/* ----- Only 16-bit mode is supported ----- */
@@ -290,6 +303,7 @@ use these in the definitions of generic macros. */
#define PCRE_EXEC PCRE_EXEC16
#define PCRE_FREE_STUDY PCRE_FREE_STUDY16
#define PCRE_STUDY PCRE_STUDY16
+#define PCRE_PATTERN_TO_HOST_BYTE_ORDER PCRE_PATTERN_TO_HOST_BYTE_ORDER16
#endif
/* ----- End of mode-specific function call macros ----- */
@@ -1855,11 +1869,6 @@ while (!done)
fprintf(outfile, "Compiled pattern%s loaded from %s\n",
do_flip? " (byte-inverted)" : "", p);
- /* Need to know if UTF-8 for printing data strings */
-
- new_info(re, NULL, PCRE_INFO_OPTIONS, &get_options);
- use_utf = (get_options & PCRE_UTF8) != 0;
-
/* Now see if there is any following study data. */
if (true_study_size != 0)
@@ -1889,12 +1898,23 @@ while (!done)
}
else fprintf(outfile, "No study data\n");
+ /* Flip the necessary bytes. */
+ if (do_flip != 0)
+ {
+ PCRE_PATTERN_TO_HOST_BYTE_ORDER(re, extra, NULL);
+ }
+
+ /* Need to know if UTF-8 for printing data strings */
+
+ new_info(re, NULL, PCRE_INFO_OPTIONS, &get_options);
+ use_utf = (get_options & PCRE_UTF8) != 0;
+
fclose(f);
goto SHOW_INFO;
}
/* In-line pattern (the usual case). Get the delimiter and seek the end of
- the pattern; if is isn't complete, read more. */
+ the pattern; if it isn't complete, read more. */
delimiter = *p++;
@@ -2252,43 +2272,6 @@ while (!done)
extra->flags |= PCRE_EXTRA_MARK;
}
- /* If the 'F' option was present, we flip the bytes of all the integer
- fields in the regex data block and the study block. This is to make it
- possible to test PCRE's handling of byte-flipped patterns, e.g. those
- compiled on a different architecture. */
-
- if (do_flip)
- {
- real_pcre *rre = (real_pcre *)re;
- rre->magic_number =
- byteflip(rre->magic_number, sizeof(rre->magic_number));
- rre->size = byteflip(rre->size, sizeof(rre->size));
- rre->options = byteflip(rre->options, sizeof(rre->options));
- rre->flags = (pcre_uint16)byteflip(rre->flags, sizeof(rre->flags));
- rre->top_bracket =
- (pcre_uint16)byteflip(rre->top_bracket, sizeof(rre->top_bracket));
- rre->top_backref =
- (pcre_uint16)byteflip(rre->top_backref, sizeof(rre->top_backref));
- rre->first_char =
- (pcre_uint16)byteflip(rre->first_char, sizeof(rre->first_char));
- rre->req_char =
- (pcre_uint16)byteflip(rre->req_char, sizeof(rre->req_char));
- rre->name_table_offset = (pcre_uint16)byteflip(rre->name_table_offset,
- sizeof(rre->name_table_offset));
- rre->name_entry_size = (pcre_uint16)byteflip(rre->name_entry_size,
- sizeof(rre->name_entry_size));
- rre->name_count = (pcre_uint16)byteflip(rre->name_count,
- sizeof(rre->name_count));
-
- if (extra != NULL)
- {
- pcre_study_data *rsd = (pcre_study_data *)(extra->study_data);
- rsd->size = byteflip(rsd->size, sizeof(rsd->size));
- rsd->flags = byteflip(rsd->flags, sizeof(rsd->flags));
- rsd->minlength = byteflip(rsd->minlength, sizeof(rsd->minlength));
- }
- }
-
/* Extract and display information from the compiled data if required. */
SHOW_INFO:
@@ -2550,6 +2533,43 @@ while (!done)
if (to_file != NULL)
{
+ /* If the 'F' option was present, we flip the bytes of all the integer
+ fields in the regex data block and the study block. This is to make it
+ possible to test PCRE's handling of byte-flipped patterns, e.g. those
+ compiled on a different architecture. */
+
+ if (do_flip)
+ {
+ real_pcre *rre = (real_pcre *)re;
+ rre->magic_number =
+ byteflip(rre->magic_number, sizeof(rre->magic_number));
+ rre->size = byteflip(rre->size, sizeof(rre->size));
+ rre->options = byteflip(rre->options, sizeof(rre->options));
+ rre->flags = (pcre_uint16)byteflip(rre->flags, sizeof(rre->flags));
+ rre->top_bracket =
+ (pcre_uint16)byteflip(rre->top_bracket, sizeof(rre->top_bracket));
+ rre->top_backref =
+ (pcre_uint16)byteflip(rre->top_backref, sizeof(rre->top_backref));
+ rre->first_char =
+ (pcre_uint16)byteflip(rre->first_char, sizeof(rre->first_char));
+ rre->req_char =
+ (pcre_uint16)byteflip(rre->req_char, sizeof(rre->req_char));
+ rre->name_table_offset = (pcre_uint16)byteflip(rre->name_table_offset,
+ sizeof(rre->name_table_offset));
+ rre->name_entry_size = (pcre_uint16)byteflip(rre->name_entry_size,
+ sizeof(rre->name_entry_size));
+ rre->name_count = (pcre_uint16)byteflip(rre->name_count,
+ sizeof(rre->name_count));
+
+ if (extra != NULL)
+ {
+ pcre_study_data *rsd = (pcre_study_data *)(extra->study_data);
+ rsd->size = byteflip(rsd->size, sizeof(rsd->size));
+ rsd->flags = byteflip(rsd->flags, sizeof(rsd->flags));
+ rsd->minlength = byteflip(rsd->minlength, sizeof(rsd->minlength));
+ }
+ }
+
FILE *f = fopen((char *)to_file, "wb");
if (f == NULL)
{