+/**
+ * Append a string representation of an address offset to an existing
+ * string.
+ *
+ * On success, the out parameter `result` will contain the base string
+ * followed by the offset string of the form "+0x1234". On failure,
+ * `result` remains unchanged.
+ *
+ * @param base_str The string to which to append an offset string
+ * @param low_addr The lower virtual memory address, the base from
+ * which the offset is computed
+ * @param high_addr The higher virtual memory address
+ * @param result Out parameter, the base string followed by the
+ * offset string
+ * @returns 0 on success, -1 on failure
+ */
+static
+int so_info_append_offset_str(const char *base_str, uint64_t low_addr,
+ uint64_t high_addr, char **result)
+{
+ int ret;
+ uint64_t offset;
+ char *_result = NULL;
+ char offset_str[ADDR_STR_LEN];
+
+ if (!base_str || !result) {
+ goto error;
+ }
+
+ offset = high_addr - low_addr;
+
+ _result = malloc(strlen(base_str) + ADDR_STR_LEN);
+ if (!_result) {
+ goto error;
+ }
+
+ ret = snprintf(offset_str, ADDR_STR_LEN, "+%#0" PRIx64, offset);
+ if (ret < 0) {
+ goto error;
+ }
+ strcpy(_result, base_str);
+ strcat(_result, offset_str);
+ *result = _result;
+
+ return 0;
+
+error:
+ free(_result);
+ return -1;
+}