2016-05-27 21 views
2

Hallo einige Probleme mit diesem Ich habe es untersucht, jemand sagte, es ist ein RegEx-Fehler mit Java, aber ich glaube nicht einmal, dass Energia Java verwendet. .. etwas verwirrt darüber, warum dieser Fehler mit C-Code auftaucht.Base 64 Encoding sehr lange Zeichenfolge Java Overflow, Arduino Energia IDE, TI CC3200

ERROR:

Exception in thread "Thread-5" java.lang.StackOverflowError 
    at java.util.regex.Pattern$Loop.match(Pattern.java:4295) 
    at java.util.regex.Pattern$GroupTail.match(Pattern.java:4227) 
    at java.util.regex.Pattern$BranchConn.match(Pattern.java:4078) 
    at java.util.regex.Pattern$CharProperty.match(Pattern.java:3345) 
    at java.util.regex.Pattern$Branch.match(Pattern.java:4114) 
    at java.util.regex.Pattern$GroupHead.match(Pattern.java:4168) 
    at java.util.regex.Pattern$Loop.match(Pattern.java:4295) 
    at java.util.regex.Pattern$GroupTail.match(Pattern.java:4227) 
    at java.util.regex.Pattern$BranchConn.match(Pattern.java:4078) 
    at java.util.regex.Pattern$CharProperty.match(Pattern.java:3345) 
    at java.util.regex.Pattern$Branch.match(Pattern.java:4114) 

... und es geht auf Hunderten von mehr Zeilen aus dem gleichen Stoff.

Wie für den regex Code:

Beachten Sie, dass ich in diesem Fall hartcodiert im Abschnitt für mein Bild (dies ist das Feld der Fehler verursacht) nur zu Testzwecken, ich mag die JSON-Nachricht übertragen mit Base64-Kodierung über das Netzwerk zu einem Web-Service, der es als Bild an meine E-Mail weiterleitet.

Wenn der Bildstring gekürzt wird, dann tritt kein Fehler auf, aber natürlich ist dies viel zu klein, um ein tatsächliches Bild zu übertragen. Schätze wirklich deine Hilfe!

// [7.12.2] Class template regex_token_iterator 
    /** 
    * Iterates over submatches in a range (or @a splits a text string). 
    * 
    * The purpose of this iterator is to enumerate all, or all specified, 
    * matches of a regular expression within a text range. The dereferenced 
    * value of an iterator of this class is a std::tr1::sub_match object. 
    */ 
    template<typename _Bi_iter, 
     typename _Ch_type = typename iterator_traits<_Bi_iter>::value_type, 
     typename _Rx_traits = regex_traits<_Ch_type> > 
    class regex_token_iterator 
    { 
    public: 
     typedef basic_regex<_Ch_type, _Rx_traits> regex_type; 
     typedef sub_match<_Bi_iter>    value_type; 
     typedef std::ptrdiff_t     difference_type; 
     typedef const value_type*     pointer; 
     typedef const value_type&     reference; 
     typedef std::forward_iterator_tag   iterator_category; 

    public: 
     /** 
     * @brief Default constructs a %regex_token_iterator. 
     * @todo Implement this function. 
     * 
     * A default-constructed %regex_token_iterator is a singular iterator 
     * that will compare equal to the one-past-the-end value for any 
     * iterator of the same type. 
     */ 
     regex_token_iterator(); 

     /** 
     * Constructs a %regex_token_iterator... 
     * @param a   [IN] The start of the text to search. 
     * @param b   [IN] One-past-the-end of the text to search. 
     * @param re   [IN] The regular expression to search for. 
     * @param submatch [IN] Which submatch to return. There are some 
     *      special values for this parameter: 
     *      - -1 each enumerated subexpression does NOT 
     *       match the regular expression (aka field 
     *       splitting) 
     *      - 0 the entire string matching the 
     *       subexpression is returned for each match 
     *       within the text. 
     *      - >0 enumerates only the indicated 
     *       subexpression from a match within the text. 
     * @param m   [IN] Policy flags for match rules. 
     * 
     * @todo Implement this function. 
     * @doctodo 
     */ 
     regex_token_iterator(_Bi_iter __a, _Bi_iter __b, const regex_type& __re, 
       int __submatch = 0, 
       regex_constants::match_flag_type __m 
       = regex_constants::match_default); 

     /** 
     * Constructs a %regex_token_iterator... 
     * @param a   [IN] The start of the text to search. 
     * @param b   [IN] One-past-the-end of the text to search. 
     * @param re   [IN] The regular expression to search for. 
     * @param submatches [IN] A list of subexpressions to return for each 
     *      regular expression match within the text. 
     * @param m   [IN] Policy flags for match rules. 
     * 
     * @todo Implement this function. 
     * @doctodo 
     */ 
     regex_token_iterator(_Bi_iter __a, _Bi_iter __b, 
       const regex_type& __re, 
       const std::vector<int>& __submatches, 
       regex_constants::match_flag_type __m 
       = regex_constants::match_default); 

     /** 
     * Constructs a %regex_token_iterator... 
     * @param a   [IN] The start of the text to search. 
     * @param b   [IN] One-past-the-end of the text to search. 
     * @param re   [IN] The regular expression to search for. 
     * @param submatches [IN] A list of subexpressions to return for each 
     *      regular expression match within the text. 
     * @param m   [IN] Policy flags for match rules. 

     * @todo Implement this function. 
     * @doctodo 
     */ 
     template<std::size_t _Nm> 
     regex_token_iterator(_Bi_iter __a, _Bi_iter __b, 
       const regex_type& __re, 
       const int (&__submatches)[_Nm], 
       regex_constants::match_flag_type __m 
       = regex_constants::match_default); 

     /** 
     * @brief Copy constructs a %regex_token_iterator. 
     * @param rhs [IN] A %regex_token_iterator to copy. 
     * @todo Implement this function. 
     */ 
     regex_token_iterator(const regex_token_iterator& __rhs); 

     /** 
     * @brief Assigns a %regex_token_iterator to another. 
     * @param rhs [IN] A %regex_token_iterator to copy. 
     * @todo Implement this function. 
     */ 
     regex_token_iterator& 
     operator=(const regex_token_iterator& __rhs); 

     /** 
     * @brief Compares a %regex_token_iterator to another for equality. 
     * @todo Implement this function. 
     */ 
     bool 
     operator==(const regex_token_iterator& __rhs); 

     /** 
     * @brief Compares a %regex_token_iterator to another for inequality. 
     * @todo Implement this function. 
     */ 
     bool 
     operator!=(const regex_token_iterator& __rhs); 

     /** 
     * @brief Dereferences a %regex_token_iterator. 
     * @todo Implement this function. 
     */ 
     const value_type& 
     operator*(); 

     /** 
     * @brief Selects a %regex_token_iterator member. 
     * @todo Implement this function. 
     */ 
     const value_type* 
     operator->(); 

     /** 
     * @brief Increments a %regex_token_iterator. 
     * @todo Implement this function. 
     */ 
     regex_token_iterator& 
     operator++(); 

     /** 
     * @brief Postincrements a %regex_token_iterator. 
     * @todo Implement this function. 
     */ 
     regex_token_iterator 
     operator++(int); 

    private: // data members for exposition only: 
     typedef regex_iterator<_Bi_iter, _Ch_type, _Rx_traits> position_iterator; 

     position_iterator __position; 
     const value_type* __result; 
     value_type  __suffix; 
     std::size_t  __n; 
     std::vector<int> __subs; 
    }; 

    /** @brief Token iterator for C-style NULL-terminated strings. */ 
    typedef regex_token_iterator<const char*>    cregex_token_iterator; 
    /** @brief Token iterator for standard strings. */ 
    typedef regex_token_iterator<string::const_iterator> sregex_token_iterator; 
#ifdef _GLIBCXX_USE_WCHAR_T 
    /** @brief Token iterator for C-style NULL-terminated wide strings. */ 
    typedef regex_token_iterator<const wchar_t*>   wcregex_token_iterator; 
    /** @brief Token iterator for standard wide-character strings. */ 
    typedef regex_token_iterator<wstring::const_iterator> wsregex_token_iterator; 
#endif 

base64.c:

#include <string.h> 

#include "base64.h" 

/* aaaack but it's fast and const should make it shared text page. */ 
static const unsigned char pr2six[256] = 
{ 
    /* ASCII table */ 
    64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 
    64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 
    64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 62, 64, 64, 64, 63, 
    52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 64, 64, 64, 64, 64, 64, 
    64, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 
    15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 64, 64, 64, 64, 64, 
    64, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 
    41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 64, 64, 64, 64, 64, 
    64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 
    64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 
    64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 
    64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 
    64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 
    64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 
    64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 
    64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64 
}; 

int Base64decode_len(const char *bufcoded) 
{ 
    int nbytesdecoded; 
    register const unsigned char *bufin; 
    register int nprbytes; 

    bufin = (const unsigned char *) bufcoded; 
    while (pr2six[*(bufin++)] <= 63); 

    nprbytes = (bufin - (const unsigned char *) bufcoded) - 1; 
    nbytesdecoded = ((nprbytes + 3)/4) * 3; 

    return nbytesdecoded + 1; 
} 

int Base64decode(char *bufplain, const char *bufcoded) 
{ 
    int nbytesdecoded; 
    register const unsigned char *bufin; 
    register unsigned char *bufout; 
    register int nprbytes; 

    bufin = (const unsigned char *) bufcoded; 
    while (pr2six[*(bufin++)] <= 63); 
    nprbytes = (bufin - (const unsigned char *) bufcoded) - 1; 
    nbytesdecoded = ((nprbytes + 3)/4) * 3; 

    bufout = (unsigned char *) bufplain; 
    bufin = (const unsigned char *) bufcoded; 

    while (nprbytes > 4) { 
    *(bufout++) = 
     (unsigned char) (pr2six[*bufin] << 2 | pr2six[bufin[1]] >> 4); 
    *(bufout++) = 
     (unsigned char) (pr2six[bufin[1]] << 4 | pr2six[bufin[2]] >> 2); 
    *(bufout++) = 
     (unsigned char) (pr2six[bufin[2]] << 6 | pr2six[bufin[3]]); 
    bufin += 4; 
    nprbytes -= 4; 
    } 

    /* Note: (nprbytes == 1) would be an error, so just ingore that case */ 
    if (nprbytes > 1) { 
    *(bufout++) = 
     (unsigned char) (pr2six[*bufin] << 2 | pr2six[bufin[1]] >> 4); 
    } 
    if (nprbytes > 2) { 
    *(bufout++) = 
     (unsigned char) (pr2six[bufin[1]] << 4 | pr2six[bufin[2]] >> 2); 
    } 
    if (nprbytes > 3) { 
    *(bufout++) = 
     (unsigned char) (pr2six[bufin[2]] << 6 | pr2six[bufin[3]]); 
    } 

    *(bufout++) = '\0'; 
    nbytesdecoded -= (4 - nprbytes) & 3; 
    return nbytesdecoded; 
} 

static const char basis_64[] = 
    "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz/"; 

int Base64encode_len(int len) 
{ 
    return ((len + 2)/3 * 4) + 1; 
} 

int Base64encode(char *encoded, const char *string, int len) 
{ 
    int i; 
    char *p; 

    p = encoded; 
    for (i = 0; i < len - 2; i += 3) { 
    *p++ = basis_64[(string[i] >> 2) & 0x3F]; 
    *p++ = basis_64[((string[i] & 0x3) << 4) | 
        ((int) (string[i + 1] & 0xF0) >> 4)]; 
    *p++ = basis_64[((string[i + 1] & 0xF) << 2) | 
        ((int) (string[i + 2] & 0xC0) >> 6)]; 
    *p++ = basis_64[string[i + 2] & 0x3F]; 
    } 
    if (i < len) { 
    *p++ = basis_64[(string[i] >> 2) & 0x3F]; 
    if (i == (len - 1)) { 
     *p++ = basis_64[((string[i] & 0x3) << 4)]; 
     *p++ = '='; 
    } 
    else { 
     *p++ = basis_64[((string[i] & 0x3) << 4) | 
         ((int) (string[i + 1] & 0xF0) >> 4)]; 
     *p++ = basis_64[((string[i + 1] & 0xF) << 2)]; 
    } 
    *p++ = '='; 
    } 

    *p++ = '\0'; 
    return p - encoded; 
} 

base64.h:

#ifndef _BASE64_H_ 
#define _BASE64_H_ 

#ifdef __cplusplus 
extern "C" { 
#endif 

int Base64encode_len(int len); 
int Base64encode(char * coded_dst, const char *plain_src,int len_plain_src); 

int Base64decode_len(const char * coded_src); 
int Base64decode(char * plain_dst, const char *coded_src); 

#ifdef __cplusplus 
} 
#endif 

#endif //_BASE64_H_ 

Zur weiteren Erläuterung: Dieser Fehler ausgelöst wird, wenn ich versuche, das JPEG-Bild einfügen mit vorcodierten base64 Text ... Ich möchte sicherstellen, dass ich ein Dummy-Bild übertragen kann, bevor ich versuche, meine eingebettete Kamera zu instanziieren. Ich bin mir ziemlich sicher, dass es nicht der Base64-Code ist, sondern der Java-Regex, von dem ich nichts weiß (einfach, dass er sich mit dem Token langer Strings beschäftigt und mit dem Fehler in Zusammenhang steht). Vielleicht versucht es ein Muster in der Zeichenkette zu finden und da es eine sehr lange zufällige Zeichenkette ist, ist es nicht in der Lage dies zu tun und dann Fehler?

+0

Der Fehler deutet wirklich darauf hin, dass es ein Problem mit einer Regex gibt, das zu viele "Schritte" benötigt, um eine Übereinstimmung zu finden. Bitte teile diesen Regex. –

+0

Wird dieser Fehler von der Energia-IDE ausgelöst, wenn Sie versuchen, diese Datei zu bearbeiten? –

+0

Der Code, den Sie freigegeben haben, ist irgendwie uninteressant - der Code, der benötigt wird, um Ihnen zu helfen, ist in der Methode 'Base64encode'. Können Sie die 'base64.h' /' base64.c' teilen? – ClasG

Antwort

0

Scheint, ein Problem mit dem IDE-Token zu sein, das für lange Zeichenfolgen im Zusammenhang mit Java Regex analysiert. Kontaktieren Sie ihr Diskussionsforum für weitere Informationen.