diff options
author | Caolán McNamara <caolanm@redhat.com> | 2014-02-08 20:46:54 +0000 |
---|---|---|
committer | Caolán McNamara <caolanm@redhat.com> | 2014-02-08 20:46:54 +0000 |
commit | d67bc9b3e6a30748c78e541ac882c2dd426b003d (patch) | |
tree | f618ce696b1d9c6a3c19ccbe632190545cc8ae65 /i18npool | |
parent | 1556dbc451f067d8744378fb9bac0eaa7ef8f5ac (diff) |
coverity#705400 Argument cannot be negative
Change-Id: Idfd95810f929d6485263c0a4fb1e24bfa31c48f8
Diffstat (limited to 'i18npool')
-rw-r--r-- | i18npool/source/localedata/saxparser.cxx | 45 |
1 files changed, 34 insertions, 11 deletions
diff --git a/i18npool/source/localedata/saxparser.cxx b/i18npool/source/localedata/saxparser.cxx index 00f0bab3bf14..0749a1cd7eca 100644 --- a/i18npool/source/localedata/saxparser.cxx +++ b/i18npool/source/localedata/saxparser.cxx @@ -111,21 +111,44 @@ public: Reference< XInputStream > createStreamFromFile( const char *pcFile ) { - FILE *f = fopen( pcFile , "rb" ); Reference< XInputStream > r; - if( f ) { - fseek( f , 0 , SEEK_END ); - size_t nLength = ftell( f ); - fseek( f , 0 , SEEK_SET ); + FILE *f = fopen( pcFile , "rb" ); - Sequence<sal_Int8> seqIn(nLength); - if (fread( seqIn.getArray() , nLength , 1 , f ) == 1) - r = Reference< XInputStream > ( new OInputStream( seqIn ) ); - else - fprintf(stderr, "failure reading %s\n", pcFile); - fclose( f ); + if (!f) + { + fprintf(stderr, "failure opening %s\n", pcFile); + return r; + } + + if (fseek( f , 0 , SEEK_END ) == -1) + { + fprintf(stderr, "failure fseeking %s\n", pcFile); + fclose(f); + return r; } + + long nLength = ftell( f ); + if (nLength == -1) + { + fprintf(stderr, "failure ftelling %s\n", pcFile); + fclose(f); + return r; + } + + if (fseek( f , 0 , SEEK_SET ) == -1) + { + fprintf(stderr, "failure fseeking %s\n", pcFile); + fclose(f); + return r; + } + + Sequence<sal_Int8> seqIn(nLength); + if (fread( seqIn.getArray(), nLength , 1 , f ) == 1) + r = Reference< XInputStream > ( new OInputStream( seqIn ) ); + else + fprintf(stderr, "failure reading %s\n", pcFile); + fclose( f ); return r; } |