X-Git-Url: http://git.indexdata.com/?p=yaz-moved-to-github.git;a=blobdiff_plain;f=odr%2Fber_oid.c;h=6c2813d30f594995e8a71b98132361f9c321350f;hp=576edfd2091804f9321b6043d56f38df8790ea60;hb=aa82967af8f06004b567ad1ed40c67b056c44e7b;hpb=396d0ccd2549e6f31cf1f9adc1c19a97d3a7b0de diff --git a/odr/ber_oid.c b/odr/ber_oid.c index 576edfd..6c2813d 100644 --- a/odr/ber_oid.c +++ b/odr/ber_oid.c @@ -4,7 +4,11 @@ * Sebastian Hammer, Adam Dickmeiss * * $Log: ber_oid.c,v $ - * Revision 1.5 1995-03-20 12:18:22 quinn + * Revision 1.6 1995-04-18 08:15:18 quinn + * Added dynamic memory allocation on encoding (whew). Code is now somewhat + * neater. We'll make the same change for decoding one day. + * + * Revision 1.5 1995/03/20 12:18:22 quinn * Fixed bug in ber_oid * * Revision 1.4 1995/03/08 12:12:11 quinn @@ -25,8 +29,7 @@ int ber_oidc(ODR o, Odr_oid *p) { - int len; - unsigned char *lenp; + int len, lenp, end; int pos, n, res, id; unsigned char octs[8]; @@ -81,9 +84,9 @@ int ber_oidc(ODR o, Odr_oid *p) case ODR_ENCODE: /* we'll allow ourselves the quiet luxury of only doing encodings shorter than 127 */ - lenp = o->bp; - o->bp++; - o->left--; + lenp = odr_tell(o); + if (odr_putc(o, 0) < 0) /* dummy */ + return 0; if (p[0] < 0 && p[1] <= 0) { o->error = ODATA; @@ -99,20 +102,23 @@ int ber_oidc(ODR o, Odr_oid *p) id >>= 7; } while (id); - if (n > o->left) + while (n--) { - o->error = OSPACE; - return 0; + unsigned char p; + + p = octs[n] | ((n > 0) << 7); + if (odr_putc(o, p) < 0) + return 0; } - o->left -= n; - while (n--) - *(o->bp++) = octs[n] | ((n > 0) << 7); } - if (ber_enclen(lenp, (o->bp - lenp) - 1, 1, 1) != 1) + end = odr_tell(o); + odr_seek(o, ODR_S_SET, lenp); + if (ber_enclen(o, (end - lenp) - 1, 1, 1) != 1) { o->error = OOTHER; return 0; } + odr_seek(o, ODR_S_END, 0); return 1; default: o->error = OOTHER; return 0; }