Skip to Content.
Sympa Menu

freetds - Re: [freetds] Solaris/SPARC: SIGBUS in unittests/array_out.c

freetds AT lists.ibiblio.org

Subject: FreeTDS Development Group

List archive

Chronological Thread  
  • From: Frediano Ziglio <freddy77 AT gmail.com>
  • To: FreeTDS Development Group <freetds AT lists.ibiblio.org>
  • Subject: Re: [freetds] Solaris/SPARC: SIGBUS in unittests/array_out.c
  • Date: Wed, 22 Sep 2010 09:22:52 +0200

I think that this patch works... too much :)
The SIGBUS is due to wrong alignment in the test. ODBC programs should
always align data passed to ODBC. Your program fix SIGBUS in the test but
probably ODBC driver will core (correctly) in the driver. I aligned
correctly record size for 64-bit platforms (it was aligned to SQLINTEGER
instead of SQLLEN).

freddy77


2010/9/21 Christos Zoulas <christos AT zoulas.com>

> On Sep 21, 12:56pm, spacey-freetds.org AT ssr.com ("Peter C. Norton") wrote:
> -- Subject: [freetds] Solaris/SPARC: SIGBUS in unittests/array_out.c
>
> | Group,
> |
> | I'm no good at alignment issues, so I'm looking for help here. I've
> | got a 64-bit build of freetds-0.83.dev.20100902:
> |
> | nortonp@ssqa1 11:54 /tmp/freetds/src/odbc/unittests $ ./array_out
> | odbctest
>
> Who in their right mind would try to run code on non Pee-Cee machines?!?
> (just kidding). Try this completely untested fix...
>
> christos
>
> Index: array_out.c
> ===================================================================
> RCS file:
> /src/twosigma/cvsroot/external/public/freetds/src/odbc/unittests/array_out.c,v
> retrieving revision 1.1.1.3
> diff -u -u -r1.1.1.3 array_out.c
> --- array_out.c 17 Jun 2009 18:31:59 -0000 1.1.1.3
> +++ array_out.c 21 Sep 2010 19:16:59 -0000
> @@ -22,13 +22,12 @@
> {
> #define ARRAY_SIZE 10
>
> - SQLUINTEGER *ids;
> + SQLUINTEGER *ids, id;
> SQLCHAR *descs;
> - SQLLEN *id_lens, *desc_lens;
> + SQLLEN *id_lens, id_len, *desc_lens, desc_len;
> SQLULEN processed;
> SQLUSMALLINT i, statuses[ARRAY_SIZE];
> - int desc_len = trunc ? 4 : 51;
> - int rec_size = 0;
> + int rec_size = 0, dlen = trunc ? 4 : 51;
> Record *rec = NULL;
> char status[20];
>
> @@ -41,37 +40,40 @@
> SQLSetStmtAttr(Statement, SQL_ATTR_ROW_BIND_TYPE,
> SQL_BIND_BY_COLUMN, 0);
>
> if (!record_bind) {
> - ids = (SQLUINTEGER *) malloc(sizeof(SQLUINTEGER) *
> ARRAY_SIZE);
> - descs = malloc(sizeof(SQLCHAR) * ARRAY_SIZE * desc_len);
> - desc_lens = (SQLLEN *) malloc(sizeof(SQLLEN) * ARRAY_SIZE);
> - id_lens = (SQLLEN *) malloc(sizeof(SQLLEN) * ARRAY_SIZE);
> + ids = malloc(sizeof(*ids) * ARRAY_SIZE);
> + descs = malloc(sizeof(*descs) * ARRAY_SIZE * dlen);
> + desc_lens = malloc(sizeof(*desc_lens) * ARRAY_SIZE);
> + id_lens = malloc(sizeof(*id_lens) * ARRAY_SIZE);
> assert(descs && ids && desc_lens && id_lens);
> } else {
> - rec_size = sizeof(Record) + ((sizeof(SQLCHAR) * desc_len +
> sizeof(SQLINTEGER) - 1) & ~(sizeof(SQLINTEGER) - 1));
> + rec_size = sizeof(Record) + ((sizeof(SQLCHAR) * dlen +
> sizeof(SQLINTEGER) - 1) & ~(sizeof(SQLINTEGER) - 1));
> SQLSetStmtAttr(Statement, SQL_ATTR_ROW_BIND_TYPE,
> int2ptr(rec_size), 0);
> - rec = (Record *) malloc(rec_size * ARRAY_SIZE);
> + rec = malloc(rec_size * ARRAY_SIZE);
> ids = &rec->id;
> id_lens = &rec->id_len;
> desc_lens = &rec->desc_len;
> descs = (SQLCHAR *) (((char *) rec) + sizeof(Record));
> }
> #define REC(f,n) (((char*)f)+rec_size*(n))
> -#define DESCS(n) (rec ? (SQLCHAR*)REC(descs,n): (descs+(n)*desc_len))
> -#define IDS(n) *(rec ? (SQLUINTEGER*)REC(ids,n) : &ids[n])
> -#define ID_LENS(n) *(rec ? (SQLLEN*)REC(id_lens,n) : &id_lens[n])
> -#define DESC_LENS(n) *(rec ? (SQLLEN*)REC(desc_lens,n) : &desc_lens[n])
> +#define DESCS(n) (rec ? (SQLCHAR*)REC(descs,n): (descs+(n)*dlen))
> +#define IDS(n) (rec ? (SQLUINTEGER*)REC(ids,n) : &ids[n])
> +#define ID_LENS(n) (rec ? (SQLLEN*)REC(id_lens,n) : &id_lens[n])
> +#define DESC_LENS(n) (rec ? (SQLLEN*)REC(desc_lens,n) : &desc_lens[n])
>
> processed = ARRAY_SIZE + 1;
> for (i = 0; i < ARRAY_SIZE; i++) {
> statuses[i] = SQL_ROW_UPDATED;
> - IDS(i) = i * 132;
> + id = i * 132;
> + memcpy(IDS(i), &id, sizeof(id));
> sprintf((char *) DESCS(i), "aaa");
> - ID_LENS(i) = 0;
> - DESC_LENS(i) = -i;
> + id_len = 0;
> + memcpy(ID_LENS(i), &id_len, sizeof(id_len));
> + desc_len = -i;
> + memcpy(DESC_LENS(i), &desc_len, sizeof(desc_len));
> }
>
> - SQLBindCol(Statement, 1, SQL_C_ULONG, &IDS(0), 0, &ID_LENS(0));
> - SQLBindCol(Statement, 2, SQL_C_CHAR, DESCS(0), desc_len,
> &DESC_LENS(0));
> + SQLBindCol(Statement, 1, SQL_C_ULONG, IDS(0), 0, ID_LENS(0));
> + SQLBindCol(Statement, 2, SQL_C_CHAR, DESCS(0), dlen, DESC_LENS(0));
>
> CHKExecDirect((SQLCHAR *) test_query, SQL_NTS, "S");
>
> @@ -85,8 +87,9 @@
> sprintf(buf, "%crow number %d", 'a' + i, i * 13);
> if (trunc)
> buf[3] = 0;
> - if (IDS(i) != i + 1 || strcmp((char *) DESCS(i), buf) != 0)
> {
> - fprintf(stderr, "Invalid result\n\tgot
> '%d|%s'\n\texpected '%d|%s'\n", (int) IDS(i), DESCS(i), i + 1, buf);
> + memcpy(&id, IDS(i), sizeof(id));
> + if (id != i + 1 || strcmp((char *) DESCS(i), buf) != 0) {
> + fprintf(stderr, "Invalid result\n\tgot
> '%d|%s'\n\texpected '%d|%s'\n", (int) id, DESCS(i), i + 1, buf);
> exit(1);
> }
>
> _______________________________________________
> FreeTDS mailing list
> FreeTDS AT lists.ibiblio.org
> http://lists.ibiblio.org/mailman/listinfo/freetds
>




Archive powered by MHonArc 2.6.24.

Top of Page