X-Git-Url: https://git.openafs.org/?p=openafs.git;a=blobdiff_plain;f=src%2Fafsmonitor%2Fafsmon-win.c;h=ed787a06b5b1382439c83be0553dcdca82125fa6;hp=c5417ff22588ae91ea11bd9d290fc2d347745cb8;hb=a9cff4ab4c9eba40145706778664318de2d89c12;hpb=4898be6278f6ff4e214dfe993c0aa31262b9036f diff --git a/src/afsmonitor/afsmon-win.c b/src/afsmonitor/afsmon-win.c index c5417ff..ed787a0 100644 --- a/src/afsmonitor/afsmon-win.c +++ b/src/afsmonitor/afsmon-win.c @@ -15,8 +15,8 @@ #include #include - #include +#include #include #include #include @@ -36,6 +36,7 @@ #include #include +#include #include "afsmonitor.h" #include "afsmon-labels.h" @@ -325,8 +326,6 @@ initLightObject(char *a_name, int a_x, int a_y, int a_width, { /*initLightObject */ struct onode *newlightp; /*Ptr to new light onode */ struct gator_light_crparams light_crparams; /*Light creation params */ - char *truncname; /*Truncated name, if needed */ - int name_len; /*True length of name */ /* the following debug statement floods the debug file */ #ifdef DEBUG_DETAILED @@ -345,20 +344,17 @@ initLightObject(char *a_name, int a_x, int a_y, int a_width, * received. */ light_crparams.onode_params.cr_type = GATOR_OBJ_LIGHT; - name_len = strlen(a_name); - if (name_len <= a_width) - sprintf(light_crparams.onode_params.cr_name, "%s", a_name); - else { - /* - * We need to truncate the given name, leaving a `*' at the end to - * show us it's been truncated. - */ - truncname = light_crparams.onode_params.cr_name; - strncpy(truncname, a_name, a_width - 1); - truncname[a_width - 1] = '*'; - truncname[a_width] = 0; - } + if (a_width >= sizeof(light_crparams.onode_params.cr_name)) + a_width = sizeof(light_crparams.onode_params.cr_name) - 1; + + if (a_width < 1) + a_width = 1; + + if (strlcpy(light_crparams.onode_params.cr_name, a_name, a_width + 1) >= a_width + 1) + /* The name is truncated, put a '*' at the end to note */ + light_crparams.onode_params.cr_name[a_width - 1] = '*'; + light_crparams.onode_params.cr_x = a_x; light_crparams.onode_params.cr_y = a_y; light_crparams.onode_params.cr_width = a_width;