diff --git a/src/stata/readstat_dta_read.c b/src/stata/readstat_dta_read.c index ce07c333..6f736704 100644 --- a/src/stata/readstat_dta_read.c +++ b/src/stata/readstat_dta_read.c @@ -317,10 +317,9 @@ static readstat_error_t dta_read_tag(dta_ctx_t *ctx, const char *tag) { static int dta_compare_strls(const void *elem1, const void *elem2) { const dta_strl_t *key = (const dta_strl_t *)elem1; const dta_strl_t *target = *(const dta_strl_t **)elem2; - if (key->o == target->o) - return key->v - target->v; - - return key->o - target->o; + if (key->o != target->o) + return (key->o > target->o) - (key->o < target->o); + return (key->v > target->v) - (key->v < target->v); } static dta_strl_t dta_interpret_strl_vo_bytes(dta_ctx_t *ctx, const unsigned char *vo_bytes) {