diff options
author | Alan Coopersmith <alan.coopersmith@oracle.com> | 2011-10-29 11:08:17 -0700 |
---|---|---|
committer | Alan Coopersmith <alan.coopersmith@oracle.com> | 2011-11-23 12:15:06 -0800 |
commit | 05d8a7f7a785eff3292f0f0537bb3902930f1b5c (patch) | |
tree | 43dc322a988c1fab65622c2aea31c2b818ce20c8 /xkb | |
parent | b967bf2af264726042e2f6ffb9ca7d234f34b56b (diff) |
Convert a bunch of sprintf to snprintf calls
This batch is the straightforward set - others are more complex and
need more analysis to determine right size to pass.
Signed-off-by: Alan Coopersmith <alan.coopersmith@oracle.com>
Reviewed-by: Jeremy Huddleston <jeremyhu@apple.com>
Diffstat (limited to 'xkb')
-rw-r--r-- | xkb/xkbtext.c | 142 |
1 files changed, 71 insertions, 71 deletions
diff --git a/xkb/xkbtext.c b/xkb/xkbtext.c index b3930f895..80348c785 100644 --- a/xkb/xkbtext.c +++ b/xkb/xkbtext.c @@ -119,7 +119,7 @@ char numBuf[20]; else if (vmodNames&&(vmodNames[ndx]!=None)) tmp= NameForAtom(vmodNames[ndx]); if (tmp==NULL) { - sprintf(numBuf,"%d",ndx); + snprintf(numBuf,sizeof(numBuf),"%d",ndx); tmp = numBuf; } @@ -227,17 +227,17 @@ char buf[100]; if (format==XkbCFile) { if (ndx<XkbNumModifiers) - sprintf(buf,"%sMapIndex",modNames[ndx]); + snprintf(buf,sizeof(buf),"%sMapIndex",modNames[ndx]); else if (ndx==XkbNoModifier) - sprintf(buf,"XkbNoModifier"); - else sprintf(buf,"0x%02x",ndx); + snprintf(buf,sizeof(buf),"XkbNoModifier"); + else snprintf(buf,sizeof(buf),"0x%02x",ndx); } else { if (ndx<XkbNumModifiers) strcpy(buf,modNames[ndx]); else if (ndx==XkbNoModifier) strcpy(buf,"none"); - else sprintf(buf,"ILLEGAL_%02x",ndx); + else snprintf(buf,sizeof(buf),"ILLEGAL_%02x",ndx); } rtrn= tbGetBuffer(strlen(buf)+1); strcpy(rtrn,buf); @@ -338,7 +338,7 @@ static char buf[32]; if (sym==NoSymbol) strcpy(buf,"NoSymbol"); - else sprintf(buf, "0x%lx", (long)sym); + else snprintf(buf, sizeof(buf), "0x%lx", (long)sym); return buf; } @@ -383,13 +383,13 @@ char *rtrn; case XkbSI_AnyOf: rtrn= siMatchText[2]; break; case XkbSI_AllOf: rtrn= siMatchText[3]; break; case XkbSI_Exactly: rtrn= siMatchText[4]; break; - default: sprintf(buf,"0x%x",type&XkbSI_OpMask); + default: snprintf(buf,sizeof(buf),"0x%x",type&XkbSI_OpMask); return buf; } if (format==XkbCFile) { if (type&XkbSI_LevelOneOnly) - sprintf(buf,"XkbSI_LevelOneOnly|XkbSI_%s",rtrn); - else sprintf(buf,"XkbSI_%s",rtrn); + snprintf(buf,sizeof(buf),"XkbSI_LevelOneOnly|XkbSI_%s",rtrn); + else snprintf(buf,sizeof(buf),"XkbSI_%s",rtrn); rtrn= buf; } return rtrn; @@ -640,12 +640,12 @@ char *rtrn; if (type<=XkbSA_LastAction) { rtrn= actionTypeNames[type]; if (format==XkbCFile) { - sprintf(buf,"XkbSA_%s",rtrn); + snprintf(buf,sizeof(buf),"XkbSA_%s",rtrn); return buf; } return rtrn; } - sprintf(buf,"Private"); + snprintf(buf,sizeof(buf),"Private"); return buf; } @@ -712,10 +712,10 @@ char tbuf[32]; act= &action->group; TryCopyStr(buf,"group=",sz); if (act->flags&XkbSA_GroupAbsolute) - sprintf(tbuf,"%d",XkbSAGroup(act)+1); + snprintf(tbuf,sizeof(tbuf),"%d",XkbSAGroup(act)+1); else if (XkbSAGroup(act)<0) - sprintf(tbuf,"%d",XkbSAGroup(act)); - else sprintf(tbuf,"+%d",XkbSAGroup(act)); + snprintf(tbuf,sizeof(tbuf),"%d",XkbSAGroup(act)); + else snprintf(tbuf,sizeof(tbuf),"+%d",XkbSAGroup(act)); TryCopyStr(buf,tbuf,sz); if (act->type==XkbSA_LockGroup) return TRUE; @@ -738,13 +738,13 @@ char tbuf[32]; x= XkbPtrActionX(act); y= XkbPtrActionY(act); if ((act->flags&XkbSA_MoveAbsoluteX)||(x<0)) - sprintf(tbuf,"x=%d",x); - else sprintf(tbuf,"x=+%d",x); + snprintf(tbuf,sizeof(tbuf),"x=%d",x); + else snprintf(tbuf,sizeof(tbuf),"x=+%d",x); TryCopyStr(buf,tbuf,sz); if ((act->flags&XkbSA_MoveAbsoluteY)||(y<0)) - sprintf(tbuf,",y=%d",y); - else sprintf(tbuf,",y=+%d",y); + snprintf(tbuf,sizeof(tbuf),",y=%d",y); + else snprintf(tbuf,sizeof(tbuf),",y=+%d",y); TryCopyStr(buf,tbuf,sz); if (act->flags&XkbSA_NoAcceleration) TryCopyStr(buf,",!accel",sz); @@ -761,12 +761,12 @@ char tbuf[32]; act= &action->btn; TryCopyStr(buf,"button=",sz); if ((act->button>0)&&(act->button<6)) { - sprintf(tbuf,"%d",act->button); + snprintf(tbuf,sizeof(tbuf),"%d",act->button); TryCopyStr(buf,tbuf,sz); } else TryCopyStr(buf,"default",sz); if (act->count>0) { - sprintf(tbuf,",count=%d",act->count); + snprintf(tbuf,sizeof(tbuf),",count=%d",act->count); TryCopyStr(buf,tbuf,sz); } if (action->type==XkbSA_LockPtrBtn) { @@ -797,8 +797,8 @@ char tbuf[32]; if (act->affect==XkbSA_AffectDfltBtn) { TryCopyStr(buf,"affect=button,button=",sz); if ((act->flags&XkbSA_DfltBtnAbsolute)||(XkbSAPtrDfltValue(act)<0)) - sprintf(tbuf,"%d",XkbSAPtrDfltValue(act)); - else sprintf(tbuf,"+%d",XkbSAPtrDfltValue(act)); + snprintf(tbuf,sizeof(tbuf),"%d",XkbSAPtrDfltValue(act)); + else snprintf(tbuf,sizeof(tbuf),"+%d",XkbSAPtrDfltValue(act)); TryCopyStr(buf,tbuf,sz); } return TRUE; @@ -814,10 +814,10 @@ char tbuf[64]; if (act->flags&XkbSA_ISODfltIsGroup) { TryCopyStr(tbuf,"group=",sz); if (act->flags&XkbSA_GroupAbsolute) - sprintf(tbuf,"%d",XkbSAGroup(act)+1); + snprintf(tbuf,sizeof(tbuf),"%d",XkbSAGroup(act)+1); else if (XkbSAGroup(act)<0) - sprintf(tbuf,"%d",XkbSAGroup(act)); - else sprintf(tbuf,"+%d",XkbSAGroup(act)); + snprintf(tbuf,sizeof(tbuf),"%d",XkbSAGroup(act)); + else snprintf(tbuf,sizeof(tbuf),"+%d",XkbSAGroup(act)); TryCopyStr(buf,tbuf,sz); } else { @@ -847,17 +847,17 @@ char tbuf[64]; nOut++; } if ((act->affect&XkbSA_ISONoAffectGroup)==0) { - sprintf(tbuf,"%sgroups",(nOut>0?"+":"")); + snprintf(tbuf,sizeof(tbuf),"%sgroups",(nOut>0?"+":"")); TryCopyStr(buf,tbuf,sz); nOut++; } if ((act->affect&XkbSA_ISONoAffectPtr)==0) { - sprintf(tbuf,"%spointer",(nOut>0?"+":"")); + snprintf(tbuf,sizeof(tbuf),"%spointer",(nOut>0?"+":"")); TryCopyStr(buf,tbuf,sz); nOut++; } if ((act->affect&XkbSA_ISONoAffectCtrls)==0) { - sprintf(tbuf,"%scontrols",(nOut>0?"+":"")); + snprintf(tbuf,sizeof(tbuf),"%scontrols",(nOut>0?"+":"")); TryCopyStr(buf,tbuf,sz); nOut++; } @@ -875,8 +875,8 @@ char tbuf[32]; act= &action->screen; if ((act->flags&XkbSA_SwitchAbsolute)||(XkbSAScreen(act)<0)) - sprintf(tbuf,"screen=%d",XkbSAScreen(act)); - else sprintf(tbuf,"screen=+%d",XkbSAScreen(act)); + snprintf(tbuf,sizeof(tbuf),"screen=%d",XkbSAScreen(act)); + else snprintf(tbuf,sizeof(tbuf),"screen=+%d",XkbSAScreen(act)); TryCopyStr(buf,tbuf,sz); if (act->flags&XkbSA_SwitchApplication) TryCopyStr(buf,",!same",sz); @@ -903,67 +903,67 @@ char tbuf[32]; else { int nOut= 0; if (tmp&XkbRepeatKeysMask) { - sprintf(tbuf,"%sRepeatKeys",(nOut>0?"+":"")); + snprintf(tbuf,sizeof(tbuf),"%sRepeatKeys",(nOut>0?"+":"")); TryCopyStr(buf,tbuf,sz); nOut++; } if (tmp&XkbSlowKeysMask) { - sprintf(tbuf,"%sSlowKeys",(nOut>0?"+":"")); + snprintf(tbuf,sizeof(tbuf),"%sSlowKeys",(nOut>0?"+":"")); TryCopyStr(buf,tbuf,sz); nOut++; } if (tmp&XkbBounceKeysMask) { - sprintf(tbuf,"%sBounceKeys",(nOut>0?"+":"")); + snprintf(tbuf,sizeof(tbuf),"%sBounceKeys",(nOut>0?"+":"")); TryCopyStr(buf,tbuf,sz); nOut++; } if (tmp&XkbStickyKeysMask) { - sprintf(tbuf,"%sStickyKeys",(nOut>0?"+":"")); + snprintf(tbuf,sizeof(tbuf),"%sStickyKeys",(nOut>0?"+":"")); TryCopyStr(buf,tbuf,sz); nOut++; } if (tmp&XkbMouseKeysMask) { - sprintf(tbuf,"%sMouseKeys",(nOut>0?"+":"")); + snprintf(tbuf,sizeof(tbuf),"%sMouseKeys",(nOut>0?"+":"")); TryCopyStr(buf,tbuf,sz); nOut++; } if (tmp&XkbMouseKeysAccelMask) { - sprintf(tbuf,"%sMouseKeysAccel",(nOut>0?"+":"")); + snprintf(tbuf,sizeof(tbuf),"%sMouseKeysAccel",(nOut>0?"+":"")); TryCopyStr(buf,tbuf,sz); nOut++; } if (tmp&XkbAccessXKeysMask) { - sprintf(tbuf,"%sAccessXKeys",(nOut>0?"+":"")); + snprintf(tbuf,sizeof(tbuf),"%sAccessXKeys",(nOut>0?"+":"")); TryCopyStr(buf,tbuf,sz); nOut++; } if (tmp&XkbAccessXTimeoutMask) { - sprintf(tbuf,"%sAccessXTimeout",(nOut>0?"+":"")); + snprintf(tbuf,sizeof(tbuf),"%sAccessXTimeout",(nOut>0?"+":"")); TryCopyStr(buf,tbuf,sz); nOut++; } if (tmp&XkbAccessXFeedbackMask) { - sprintf(tbuf,"%sAccessXFeedback",(nOut>0?"+":"")); + snprintf(tbuf,sizeof(tbuf),"%sAccessXFeedback",(nOut>0?"+":"")); TryCopyStr(buf,tbuf,sz); nOut++; } if (tmp&XkbAudibleBellMask) { - sprintf(tbuf,"%sAudibleBell",(nOut>0?"+":"")); + snprintf(tbuf,sizeof(tbuf),"%sAudibleBell",(nOut>0?"+":"")); TryCopyStr(buf,tbuf,sz); nOut++; } if (tmp&XkbOverlay1Mask) { - sprintf(tbuf,"%sOverlay1",(nOut>0?"+":"")); + snprintf(tbuf,sizeof(tbuf),"%sOverlay1",(nOut>0?"+":"")); TryCopyStr(buf,tbuf,sz); nOut++; } if (tmp&XkbOverlay2Mask) { - sprintf(tbuf,"%sOverlay2",(nOut>0?"+":"")); + snprintf(tbuf,sizeof(tbuf),"%sOverlay2",(nOut>0?"+":"")); TryCopyStr(buf,tbuf,sz); nOut++; } if (tmp&XkbIgnoreGroupLockMask) { - sprintf(tbuf,"%sIgnoreGroupLock",(nOut>0?"+":"")); + snprintf(tbuf,sizeof(tbuf),"%sIgnoreGroupLock",(nOut>0?"+":"")); TryCopyStr(buf,tbuf,sz); nOut++; } @@ -990,12 +990,12 @@ char tbuf[32]; else if (act->flags&XkbSA_MessageOnPress) TryCopyStr(buf,"KeyPress",sz); else TryCopyStr(buf,"KeyRelease",sz); - sprintf(tbuf,",data[0]=0x%02x",act->message[0]); TryCopyStr(buf,tbuf,sz); - sprintf(tbuf,",data[1]=0x%02x",act->message[1]); TryCopyStr(buf,tbuf,sz); - sprintf(tbuf,",data[2]=0x%02x",act->message[2]); TryCopyStr(buf,tbuf,sz); - sprintf(tbuf,",data[3]=0x%02x",act->message[3]); TryCopyStr(buf,tbuf,sz); - sprintf(tbuf,",data[4]=0x%02x",act->message[4]); TryCopyStr(buf,tbuf,sz); - sprintf(tbuf,",data[5]=0x%02x",act->message[5]); TryCopyStr(buf,tbuf,sz); + snprintf(tbuf,sizeof(tbuf),",data[0]=0x%02x",act->message[0]); TryCopyStr(buf,tbuf,sz); + snprintf(tbuf,sizeof(tbuf),",data[1]=0x%02x",act->message[1]); TryCopyStr(buf,tbuf,sz); + snprintf(tbuf,sizeof(tbuf),",data[2]=0x%02x",act->message[2]); TryCopyStr(buf,tbuf,sz); + snprintf(tbuf,sizeof(tbuf),",data[3]=0x%02x",act->message[3]); TryCopyStr(buf,tbuf,sz); + snprintf(tbuf,sizeof(tbuf),",data[4]=0x%02x",act->message[4]); TryCopyStr(buf,tbuf,sz); + snprintf(tbuf,sizeof(tbuf),",data[5]=0x%02x",act->message[5]); TryCopyStr(buf,tbuf,sz); return TRUE; } @@ -1016,9 +1016,9 @@ unsigned vmods,vmods_mask; (xkb->names->keys[kc].name[0]!='\0')) { char *kn; kn= XkbKeyNameText(xkb->names->keys[kc].name,XkbXKBFile); - sprintf(tbuf,"key=%s",kn); + snprintf(tbuf,sizeof(tbuf),"key=%s",kn); } - else sprintf(tbuf,"key=%d",kc); + else snprintf(tbuf,sizeof(tbuf),"key=%d",kc); TryCopyStr(buf,tbuf,sz); if ((act->mods_mask==0)&&(vmods_mask==0)) return TRUE; @@ -1054,12 +1054,12 @@ XkbDeviceBtnAction * act; char tbuf[32]; act= &action->devbtn; - sprintf(tbuf,"device= %d",act->device); TryCopyStr(buf,tbuf,sz); + snprintf(tbuf,sizeof(tbuf),"device= %d",act->device); TryCopyStr(buf,tbuf,sz); TryCopyStr(buf,",button=",sz); - sprintf(tbuf,"%d",act->button); + snprintf(tbuf,sizeof(tbuf),"%d",act->button); TryCopyStr(buf,tbuf,sz); if (act->count>0) { - sprintf(tbuf,",count=%d",act->count); + snprintf(tbuf,sizeof(tbuf),",count=%d",act->count); TryCopyStr(buf,tbuf,sz); } if (action->type==XkbSA_LockDeviceBtn) { @@ -1086,14 +1086,14 @@ XkbAnyAction * act; char tbuf[32]; act= &action->any; - sprintf(tbuf,"type=0x%02x",act->type); TryCopyStr(buf,tbuf,sz); - sprintf(tbuf,",data[0]=0x%02x",act->data[0]); TryCopyStr(buf,tbuf,sz); - sprintf(tbuf,",data[1]=0x%02x",act->data[1]); TryCopyStr(buf,tbuf,sz); - sprintf(tbuf,",data[2]=0x%02x",act->data[2]); TryCopyStr(buf,tbuf,sz); - sprintf(tbuf,",data[3]=0x%02x",act->data[3]); TryCopyStr(buf,tbuf,sz); - sprintf(tbuf,",data[4]=0x%02x",act->data[4]); TryCopyStr(buf,tbuf,sz); - sprintf(tbuf,",data[5]=0x%02x",act->data[5]); TryCopyStr(buf,tbuf,sz); - sprintf(tbuf,",data[6]=0x%02x",act->data[6]); TryCopyStr(buf,tbuf,sz); + snprintf(tbuf,sizeof(tbuf),"type=0x%02x",act->type); TryCopyStr(buf,tbuf,sz); + snprintf(tbuf,sizeof(tbuf),",data[0]=0x%02x",act->data[0]); TryCopyStr(buf,tbuf,sz); + snprintf(tbuf,sizeof(tbuf),",data[1]=0x%02x",act->data[1]); TryCopyStr(buf,tbuf,sz); + snprintf(tbuf,sizeof(tbuf),",data[2]=0x%02x",act->data[2]); TryCopyStr(buf,tbuf,sz); + snprintf(tbuf,sizeof(tbuf),",data[3]=0x%02x",act->data[3]); TryCopyStr(buf,tbuf,sz); + snprintf(tbuf,sizeof(tbuf),",data[4]=0x%02x",act->data[4]); TryCopyStr(buf,tbuf,sz); + snprintf(tbuf,sizeof(tbuf),",data[5]=0x%02x",act->data[5]); TryCopyStr(buf,tbuf,sz); + snprintf(tbuf,sizeof(tbuf),",data[6]=0x%02x",act->data[6]); TryCopyStr(buf,tbuf,sz); return TRUE; } @@ -1135,7 +1135,7 @@ char buf[ACTION_SZ],*tmp; int sz; if (format==XkbCFile) { - sprintf(buf, + snprintf(buf,sizeof(buf), "{ %20s, { 0x%02x, 0x%02x, 0x%02x, 0x%02x, 0x%02x, 0x%02x, 0x%02x } }", XkbActionTypeText(action->type,XkbCFile), action->any.data[0],action->any.data[1],action->any.data[2], @@ -1143,7 +1143,7 @@ int sz; action->any.data[6]); } else { - sprintf(buf,"%s(",XkbActionTypeText(action->type,XkbXKBFile)); + snprintf(buf,sizeof(buf),"%s(",XkbActionTypeText(action->type,XkbXKBFile)); sz= ACTION_SZ-strlen(buf)+2; /* room for close paren and NULL */ if (action->type<(unsigned)XkbSA_NumActions) (*copyActionArgs[action->type])(xkb,action,buf,&sz); @@ -1163,8 +1163,8 @@ char buf[256],*tmp; if (format==XkbCFile) { if (behavior->type==XkbKB_Default) - sprintf(buf,"{ 0, 0 }"); - else sprintf(buf,"{ %3d, 0x%02x }",behavior->type,behavior->data); + snprintf(buf,sizeof(buf),"{ 0, 0 }"); + else snprintf(buf,sizeof(buf),"{ %3d, 0x%02x }",behavior->type,behavior->data); } else { unsigned type,permanent; @@ -1172,14 +1172,14 @@ char buf[256],*tmp; permanent=((behavior->type&XkbKB_Permanent)!=0); if (type==XkbKB_Lock) { - sprintf(buf,"lock= %s",(permanent?"Permanent":"TRUE")); + snprintf(buf,sizeof(buf),"lock= %s",(permanent?"Permanent":"TRUE")); } else if (type==XkbKB_RadioGroup) { int g; char *tmp; g= ((behavior->data)&(~XkbKB_RGAllowNone))+1; if (XkbKB_RGAllowNone&behavior->data) { - sprintf(buf,"allowNone,"); + snprintf(buf,sizeof(buf),"allowNone,"); tmp= &buf[strlen(buf)]; } else tmp= buf; @@ -1197,12 +1197,12 @@ char buf[256],*tmp; kn= XkbKeyNameText(xkb->names->keys[kc].name,XkbXKBFile); else { static char tbuf[8]; - sprintf(tbuf,"%d",kc); + snprintf(tbuf,sizeof(tbuf),"%d",kc); kn= tbuf; } if (permanent) - sprintf(buf,"permanentOverlay%d= %s",ndx,kn); - else sprintf(buf,"overlay%d= %s",ndx,kn); + snprintf(buf,sizeof(buf),"permanentOverlay%d= %s",ndx,kn); + else snprintf(buf,sizeof(buf),"overlay%d= %s",ndx,kn); } } tmp= tbGetBuffer(strlen(buf)+1); |