yes, substring. You don't need to do a Math.min; substring with a longer index than the length of the string ends at the original length.
But!
document.getElementById("foo").innerHTML = "<a href='" + pathname +"'>" + pathname +"</a>"
This is a mistake. What if document.referrer had an apostrophe in? Or various other characters that have special meaning in HTML. In the worst case, attacker code in the referrer could inject JavaScript into your page, which is a XSS security hole.
Whilst it's possible to escape the characters in pathname manually to stop this happening, it's a bit of a pain. You're better off using DOM methods than fiddling with innerHTML strings.
if (document.referrer) {
var trimmed= document.referrer.substring(0, 64);
var link= document.createElement('a');
link.href= document.referrer;
link.appendChild(document.createTextNode(trimmed));
document.getElementById('foo').appendChild(link);
}