Clean up signedness warnings and 64-bit bugs in recent psql printing
authorTom Lane
Fri, 10 Feb 2006 22:29:06 +0000 (22:29 +0000)
committerTom Lane
Fri, 10 Feb 2006 22:29:06 +0000 (22:29 +0000)
patch.  Martijn van Oosterhout and Tom Lane

src/bin/psql/mbprint.c
src/bin/psql/print.c

index 68850b196893de1df89a023ef45423cfc2365aa6..871d7fae9796683ee7982abdff5e9fd552e40643 100644 (file)
@@ -3,7 +3,7 @@
  *
  * Copyright (c) 2000-2005, PostgreSQL Global Development Group
  *
- * $PostgreSQL: pgsql/src/bin/psql/mbprint.c,v 1.19 2006/02/10 00:39:04 momjian Exp $
+ * $PostgreSQL: pgsql/src/bin/psql/mbprint.c,v 1.20 2006/02/10 22:29:06 tgl Exp $
  */
 
 #include "postgres_fe.h"
@@ -158,11 +158,11 @@ pg_wcswidth(const unsigned char *pwcs, size_t len, int encoding)
    {
        int chlen, chwidth;
 
-       chlen = PQmblen(pwcs, encoding);
+       chlen = PQmblen((const char*) pwcs, encoding);
        if (chlen > len)
            break;     /* Invalid string */
            
-       chwidth = PQdsplen(pwcs, encoding);
+       chwidth = PQdsplen((const char *) pwcs, encoding);
        
        if (chwidth > 0)
            width += chwidth;
@@ -191,10 +191,10 @@ pg_wcssize(unsigned char *pwcs, size_t len, int encoding, int *result_width,
 
    for (; *pwcs && len > 0; pwcs += chlen)
    {
-       chlen = PQmblen(pwcs, encoding);
+       chlen = PQmblen((char *) pwcs, encoding);
        if (len < (size_t)chlen)
            break;
-       w = PQdsplen(pwcs, encoding);
+       w = PQdsplen((char *) pwcs, encoding);
 
        if (chlen == 1)   /* ASCII char */
        {
@@ -256,15 +256,14 @@ pg_wcsformat(unsigned char *pwcs, size_t len, int encoding,
    int         w,
                chlen = 0;
    int linewidth = 0;
-   
-   char *ptr = lines->ptr;   /* Pointer to data area */
+   unsigned char *ptr = lines->ptr;   /* Pointer to data area */
 
    for (; *pwcs && len > 0; pwcs += chlen)
    {
-       chlen = PQmblen(pwcs,encoding);
+       chlen = PQmblen((char *) pwcs,encoding);
        if (len < (size_t)chlen)
            break;
-       w = PQdsplen(pwcs,encoding);
+       w = PQdsplen((char *) pwcs,encoding);
 
        if (chlen == 1)   /* single byte char char */
        {
@@ -282,13 +281,13 @@ pg_wcsformat(unsigned char *pwcs, size_t len, int encoding,
            }
            else if (*pwcs == '\r')   /* Linefeed */
            {
-               strcpy(ptr, "\\r");
+               strcpy((char *) ptr, "\\r");
                linewidth += 2;
                ptr += 2;
            }
            else if (w <= 0)  /* Other control char */
            {
-               sprintf(ptr, "\\x%02X", *pwcs);
+               sprintf((char *) ptr, "\\x%02X", *pwcs);
                linewidth += 4;
                ptr += 4;
            }
@@ -301,13 +300,13 @@ pg_wcsformat(unsigned char *pwcs, size_t len, int encoding,
        else if (w <= 0)  /* Non-ascii control char */
        {
            if (encoding == PG_UTF8)
-               sprintf(ptr, "\\u%04X", utf2ucs(pwcs));
+               sprintf((char *) ptr, "\\u%04X", utf2ucs(pwcs));
            else
                /* This case cannot happen in the current
                 * code because only UTF-8 signals multibyte
                 * control characters. But we may need to
                 * support it at some stage */
-               sprintf(ptr, "\\u????");
+               sprintf((char *) ptr, "\\u????");
                
            ptr += 6;
            linewidth += 6;
index 67e0f433437dfee852c999438c1bafbda59ada95..64c644784f137ceb552e0e786a4ded6c5a959adf 100644 (file)
@@ -3,7 +3,7 @@
  *
  * Copyright (c) 2000-2005, PostgreSQL Global Development Group
  *
- * $PostgreSQL: pgsql/src/bin/psql/print.c,v 1.81 2006/02/10 15:48:05 momjian Exp $
+ * $PostgreSQL: pgsql/src/bin/psql/print.c,v 1.82 2006/02/10 22:29:06 tgl Exp $
  */
 #include "postgres_fe.h"
 #include "common.h"
@@ -357,8 +357,8 @@ print_aligned_text(const char *title, const char *const * headers,
 {
    unsigned int col_count = 0;
    unsigned int cell_count = 0;
-   unsigned int i,
-               tmp;
+   unsigned int i;
+   int tmp;
    unsigned int *widths,
                total_w;
    unsigned int *heights;
@@ -583,17 +583,22 @@ print_aligned_text(const char *title, const char *const * headers,
                    {
                        if (opt_numeric_locale)
                        {
-                           /* Assumption: This code used only on strings
+                           /*
+                            * Assumption: This code used only on strings
                             * without multibyte characters, otherwise
                             * this_line->width < strlen(this_ptr) and we
-                            * get an overflow */
-
-                           char *my_cell = format_numeric_locale(this_line->ptr);
-                           fprintf(fout, "%*s%s", widths[i % col_count] - strlen(my_cell), "", my_cell);
+                            * get an overflow
+                            */
+                           char *my_cell = format_numeric_locale((char *) this_line->ptr);
+                           fprintf(fout, "%*s%s",
+                                   (int) (widths[i % col_count] - strlen(my_cell)), "",
+                                   my_cell);
                            free(my_cell);
                        }
                        else
-                           fprintf(fout, "%*s%s", widths[j] - this_line->width, "", this_line->ptr);
+                           fprintf(fout, "%*s%s",
+                                   widths[j] - this_line->width, "",
+                                   this_line->ptr);
                    }
                    else
                        fprintf(fout, "%-s%*s", this_line->ptr,
@@ -665,13 +670,13 @@ print_aligned_vertical(const char *title, const char *const * headers,
    unsigned int record = 1;
    const char *const * ptr;
    unsigned int i,
-               tmp = 0,
                hwidth = 0,
                dwidth = 0,
                hheight = 1,
                dheight = 1,
                hformatsize = 0,
                dformatsize = 0;
+   int tmp = 0;
    char       *divider;
    unsigned int cell_count = 0;
    struct lineptr *hlineptr, *dlineptr;
@@ -823,11 +828,12 @@ print_aligned_vertical(const char *title, const char *const * headers,
            {
                if (opt_align[i % col_count] == 'r' && opt_numeric_locale)
                {
-                   char *my_cell = format_numeric_locale(dlineptr[line_count].ptr);
+                   char *my_cell = format_numeric_locale((char *) dlineptr[line_count].ptr);
                    if (opt_border < 2)
                        fprintf(fout, "%s\n", my_cell);
                    else
-                       fprintf(fout, "%-s%*s |\n", my_cell, dwidth - strlen(my_cell), "");
+                       fprintf(fout, "%-s%*s |\n", my_cell,
+                               (int) (dwidth - strlen(my_cell)), "");
                    free(my_cell);
                }
                else
@@ -1753,7 +1759,8 @@ printQuery(const PGresult *result, const printQueryOpt *opt, FILE *fout, FILE *f
    headers = pg_local_calloc(nfields + 1, sizeof(*headers));
 
    for (i = 0; i < nfields; i++)
-       headers[i] = mbvalidate(PQfname(result, i), opt->topt.encoding);
+       headers[i] = (char*) mbvalidate((unsigned char *) PQfname(result, i),
+                                       opt->topt.encoding);
 
    /* set cells */
    ncells = PQntuples(result) * nfields;
@@ -1764,7 +1771,9 @@ printQuery(const PGresult *result, const printQueryOpt *opt, FILE *fout, FILE *f
        if (PQgetisnull(result, i / nfields, i % nfields))
            cells[i] = opt->nullPrint ? opt->nullPrint : "";
        else
-           cells[i] = mbvalidate(PQgetvalue(result, i / nfields, i % nfields), opt->topt.encoding);
+           cells[i] = (char*)
+               mbvalidate((unsigned char*) PQgetvalue(result, i / nfields, i % nfields),
+                          opt->topt.encoding);
    }
 
    /* set footers */