数组处理函数(获取字符数组中一定长度的字符,修改字符数组的某个字符)

希望大家仔细看一下 希望能够找到一些漏洞,能让这些函数更加完善一些

 

/**
*retval:
 -1:length input error
 0:buf input NULL
 1:get date success
*function:
 Get a part of words from array,and save to outBuf
*parameter:
 start:position of start
 length: length that  you want to get
 inBuf:word from
 outBuf:word saving to
*/
static const int readFromBuf(const unsigned int start,unsigned int length,const  char*  inBuf, char* const outBuf)
{
 if(start > strlen(inBuf) || start <= 0 || length > (strlen(inBuf) - start))
 {
  return -1;
 }
 if(NULL == inBuf || NULL == outBuf)
 {
  return 0;
 }
  char *inTemp = NULL;
  char *outTemp = NULL;

 inTemp = (char*)(inBuf + start - 1);
 outTemp = outBuf;

 while(length--)
 {
  *outTemp++ = *inTemp++;
 }
 return 1;
}

 

/**
*retval:
 -1:position too long
 0:inBuf is NULL
 1:write success
*/
static const int writeByteToBuf(const unsigned int position,char *inBuf,char byte)
{
 if(position > strlen(inBuf) || 0 == position)
 {
  return -1;
 }
 if(NULL == inBuf)
 {
  return 0;
 }
 *(inBuf+position-1) = byte;

 return 1;
}

 

posted on 2014-04-17 19:39  __zc__Linux__  阅读(293)  评论(0编辑  收藏  举报