Skip to content

Commit

Permalink
Trim interface length if its too big for window
Browse files Browse the repository at this point in the history
  • Loading branch information
kala13x committed Nov 26, 2024
1 parent 0286574 commit d4d61a9
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 12 deletions.
8 changes: 0 additions & 8 deletions src/sys/xtop.c
Original file line number Diff line number Diff line change
Expand Up @@ -138,14 +138,6 @@ int XTop_GetNetworkStats(xtop_stats_t *pStats, xarray_t *pIfaces)
if (pDstIface == NULL) continue;

memcpy(pDstIface, pSrcIface, sizeof(xnet_iface_t));
if (strnlen(pDstIface->sName, sizeof(pDstIface->sName) - 1) > 12)
{
pDstIface->sName[9] = '.';
pDstIface->sName[10] = '.';
pDstIface->sName[11] = '.';
pDstIface->sName[12] = XSTR_NUL;
}

if (XArray_AddData(pIfaces, pDstIface, 0) < 0) free(pDstIface);
}

Expand Down
2 changes: 1 addition & 1 deletion src/xver.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

#define XUTILS_VERSION_MAX 2
#define XUTILS_VERSION_MIN 6
#define XUTILS_BUILD_NUMBER 12
#define XUTILS_BUILD_NUMBER 13

#ifdef __cplusplus
extern "C" {
Expand Down
16 changes: 13 additions & 3 deletions tools/xtop.c
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
#include "api.h"

#define XTOP_VERSION_MAJ 1
#define XTOP_VERSION_MIN 4
#define XTOP_VERSION_MIN 5

#define XTOP_SORT_DISABLE 0
#define XTOP_SORT_BUSY 1
Expand Down Expand Up @@ -760,8 +760,18 @@ XSTATUS XTOPApp_AddNetworkInfo(xcli_win_t *pWin, xtop_args_t *pArgs, xarray_t *p
if (xstrused(pIface->sName) == XTRUE && nTrackLen > 0 && nTrackID < 0 &&
!strncmp(pArgs->sName, pIface->sName, nTrackLen)) nTrackID = (int)i;

size_t nNextLength = strlen(pIface->sName);
if (nNextLength > nLength) nLength = nNextLength;
size_t nNextLength = strnlen(pIface->sName, sizeof(pIface->sName));
if (nNextLength > 12)
{
nNextLength = 12;
pIface->sName[9] = '.';
pIface->sName[10] = '.';
pIface->sName[11] = '.';
pIface->sName[12] = XSTR_NUL;
}

if (nNextLength > nLength)
nLength = nNextLength;
}

/* If iface length is less than "total", take "total" length as maximum */
Expand Down

0 comments on commit d4d61a9

Please sign in to comment.