- {
- /* Convert the string to UTF-8 and build a translation table
- from offsets into s to offsets into the translated string. */
- size_t *offsets = (size_t *) malloc (n * sizeof (size_t));
-
- if (offsets != NULL)
- {
- uint8_t *t = NULL;
- size_t m;
- if (u8_conv_from_encoding (encoding, iconveh_question_mark,
- s, n, offsets, &t, &m)
- == 0)
- {
- char *q = (char *) malloc (m);
-
- if (q != NULL)
- {
- size_t i;
-
- /* Determine the possible line breaks of the UTF-8
- string. */
- u8_possible_linebreaks (t, m, encoding, q);
-
- /* Translate the result back to the original string. */
- memset (p, UC_BREAK_PROHIBITED, n);
- for (i = 0; i < n; i++)
- if (offsets[i] != (size_t)(-1))
- p[i] = q[offsets[i]];
-
- free (q);
- free (t);
- free (offsets);
- return;
- }
- free (t);
- }
- free (offsets);
- }
-
- /* Impossible to convert. */
+ {
+ /* Convert the string to UTF-8 and build a translation table
+ from offsets into s to offsets into the translated string. */
+ size_t *offsets = (size_t *) malloc (n * sizeof (size_t));
+
+ if (offsets != NULL)
+ {
+ uint8_t *t;
+ size_t m;
+
+ t = u8_conv_from_encoding (encoding, iconveh_question_mark,
+ s, n, offsets, NULL, &m);
+ if (t != NULL)
+ {
+ char *q = (char *) (m > 0 ? malloc (m) : NULL);
+
+ if (m == 0 || q != NULL)
+ {
+ size_t i;
+
+ /* Determine the possible line breaks of the UTF-8
+ string. */
+ u8_possible_linebreaks (t, m, encoding, q);
+
+ /* Translate the result back to the original string. */
+ memset (p, UC_BREAK_PROHIBITED, n);
+ for (i = 0; i < n; i++)
+ if (offsets[i] != (size_t)(-1))
+ p[i] = q[offsets[i]];
+
+ free (q);
+ free (t);
+ free (offsets);
+ return;
+ }
+ free (t);
+ }
+ free (offsets);
+ }
+
+ /* Impossible to convert. */