sort: use asprintf(3) instead of malloc + snprintf(3)
(cherry picked from commit 48a53cc4849555f1a0b805adddb9f517a305a2ae)