Replace broken str* functions with safe versions.
[platform/upstream/flac.git] / src / share / utf8 / utf8.c
index 303fe23..63827c7 100644 (file)
@@ -14,9 +14,9 @@
  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  * GNU General Public License for more details.
  * 
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
  */
 
 /*
@@ -31,6 +31,7 @@
 #include <string.h>
 
 #include "share/alloc.h"
+#include "share/safe_str.h"
 #include "utf8.h"
 #include "charset.h"
 
@@ -155,7 +156,7 @@ int utf8_encode(const char *from, char **to)
 
        if(wchars == 0)
        {
-               fprintf(stderr, "Unicode translation error %d\n", GetLastError());
+               fprintf(stderr, "Unicode translation error %d\n", (int)GetLastError());
                return -1;
        }
 
@@ -174,7 +175,7 @@ int utf8_encode(const char *from, char **to)
        if(err != wchars)
        {
                free(unicode);
-               fprintf(stderr, "Unicode translation error %d\n", GetLastError());
+               fprintf(stderr, "Unicode translation error %d\n", (int)GetLastError());
                return -1;
        }
 
@@ -210,7 +211,7 @@ int utf8_decode(const char *from, char **to)
 
     if(chars == 0)
     {
-        fprintf(stderr, "Unicode translation error %d\n", GetLastError());
+        fprintf(stderr, "Unicode translation error %d\n", (int)GetLastError());
         free(unicode);
         return -1;
     }
@@ -227,7 +228,7 @@ int utf8_decode(const char *from, char **to)
             -1, *to, chars, NULL, NULL);
     if(err != chars)
     {
-        fprintf(stderr, "Unicode translation error %d\n", GetLastError());
+        fprintf(stderr, "Unicode translation error %d\n", (int)GetLastError());
         free(unicode);
         free(*to);
         *to = NULL;
@@ -298,7 +299,7 @@ static int convert_string(const char *fromcode, const char *tocode,
   s = safe_malloc_add_2op_(fromlen, /*+*/1);
   if (!s)
     return -1;
-  strcpy(s, from);
+  safe_strncpy(s, from, fromlen + 1);
   *to = s;
   for (; *s; s++)
     if (*s & ~0x7f)