diff options
author | nicolas.zilio@hotmail.fr <> | 2015-09-15 19:25:47 +0200 |
---|---|---|
committer | nicolas.zilio@hotmail.fr <> | 2015-09-15 19:25:47 +0200 |
commit | 16556c4b24e37a4d451b7a85a5d260c4ee9828cb (patch) | |
tree | 542b3e110aa2d7883f5d5c4ab62ddbaa1e145d05 | |
parent | e43b676d8294f37410ea0fa1f9fa39d10df64408 (diff) | |
download | pcitool-16556c4b24e37a4d451b7a85a5d260c4ee9828cb.tar.gz pcitool-16556c4b24e37a4d451b7a85a5d260c4ee9828cb.tar.bz2 pcitool-16556c4b24e37a4d451b7a85a5d260c4ee9828cb.tar.xz pcitool-16556c4b24e37a4d451b7a85a5d260c4ee9828cb.zip |
no more realloc in op enum
-rw-r--r-- | pcilib/views.c | 9 | ||||
-rw-r--r-- | pcitool/cli.c | 14 |
2 files changed, 11 insertions, 12 deletions
diff --git a/pcilib/views.c b/pcilib/views.c index 83c5827..2011d86 100644 --- a/pcilib/views.c +++ b/pcilib/views.c @@ -139,7 +139,7 @@ int pcilib_read_view(pcilib_t *ctx, const char *bank, const char *regname, const for(j=0;ctx->register_ctx[i].views[j].name;j++){ if(!(strcasecmp("name",ctx->register_ctx[i].views[j].base_unit.name))){/*if we asked for the unit "name"*/ - err=ctx->register_ctx[i].views[j].op(ctx,ctx->register_ctx[i].views[j].parameters,value/*the command name*/,0,&temp_value,0,&(ctx->register_ctx[i].views[j])); + err=ctx->register_ctx[i].views[j].op(ctx,ctx->register_ctx[i].views[j].parameters,value/*the command name*/,0,&temp_value,value_size,NULL); if(err){ pcilib_error("can't read from the register with the enum view"); return PCILIB_ERROR_FAILED; @@ -198,7 +198,7 @@ int pcilib_write_view(pcilib_t *ctx, const char *bank, const char *regname, cons ok=1; break; }else if(!(strcasecmp(ctx->register_ctx[i].views[j].base_unit.name,(char*)unit))){/*in this case we asked for then name of the view in unit*/ - temp_value=*(pcilib_register_value_t*)value /*the value to put in the register*/; + //temp_value=*(pcilib_register_value_t*)value /*the value to put in the register*/; err=ctx->register_ctx[i].views[j].op(ctx,ctx->register_ctx[i].views[j].parameters, (char*)unit, 1, &temp_value,0,&(ctx->register_ctx[i].views[j])); if(err){ pcilib_error("can't write to the register with the formula view %s", unit); @@ -249,7 +249,10 @@ int operation_enum(pcilib_t *ctx, void *params, char* name, int view2reg, pcilib }else if (view2reg==0){ for(j=0; ((pcilib_enum_t*)(params))[j].name;j++){ if (*regval<=((pcilib_enum_t*)(params))[j].max && *regval>=((pcilib_enum_t*)(params))[j].min){ - name=(char*)realloc(name,strlen(((pcilib_enum_t*)(params))[j].name)*sizeof(char)); + if(viewval_size<strlen(((pcilib_enum_t*)(params))[j].name)){ + pcilib_error("the string to contain the enum command is too tight"); + return PCILIB_ERROR_MEMORY; + } strncpy(name,((pcilib_enum_t*)(params))[j].name, strlen(((pcilib_enum_t*)(params))[j].name)); k=strlen(((pcilib_enum_t*)(params))[j].name); name[k]='\0'; diff --git a/pcitool/cli.c b/pcitool/cli.c index aa80b72..b168d16 100644 --- a/pcitool/cli.c +++ b/pcitool/cli.c @@ -1047,7 +1047,7 @@ int ReadRegister(pcilib_t *handle, const pcilib_model_description_t *model_info, printf("\n"); } }else if(reg && (s1=strchr(fullreg,'/'))){ - char* enum_command=malloc(sizeof(char*)); + char* enum_command=malloc(50*sizeof(char)); if(!enum_command){ printf("Error allocating memory for the result\n"); return PCILIB_ERROR_MEMORY; @@ -1055,26 +1055,22 @@ int ReadRegister(pcilib_t *handle, const pcilib_model_description_t *model_info, *s1=0; regname=fullreg; viewname=s1+1; - printf("regname %s, viewname %s\n",regname,viewname); if(!strcasecmp(viewname,"name")){ - err = pcilib_read_view(handle,bank,regname,viewname,sizeof(char*),enum_command); + err = pcilib_read_view(handle,bank,regname,viewname,50*sizeof(char),enum_command); if (err) printf("Error reading register %s with an enum view\n", reg); else { printf("%s = %s\n", regname, (char*)enum_command); } free(enum_command); }else{ - pcilib_register_t regid = pcilib_find_register(handle, bank, regname); - bank_id = pcilib_find_register_bank_by_addr(handle, model_info->registers[regid].bank); - format = model_info->banks[bank_id].format; - if (!format) format = "%lu"; + format = "%lf"; err = pcilib_read_view(handle,bank,regname,viewname,sizeof(pcilib_register_value_t),&value); if (err) printf("Error reading register %s with a formula view\n", reg); else { printf("%s = ", reg); printf(format, value); - printf("\n"); + printf("%s\n",viewname); } } } else { @@ -1338,7 +1334,7 @@ int WriteRegister(pcilib_t *handle, const pcilib_model_description_t *model_info if((regname)){ char *view_name; view_name=s1+1;; - err = pcilib_write_view(handle,bank,regname,view_name,sizeof(pcilib_register_value_t),&value); + err = pcilib_write_view(handle,bank,regname,view_name,0,&value); if (err) printf("Error writing register %s using view %s\n",regname,view_name); free(fullregister); }else{ |