标签: hardcoded

C硬编码数组作为memcpy参数

我想传入一个硬编码的char数组作为sourcememcpy 的参数...像这样:

memcpy(dest, {0xE3,0x83,0xA2,0xA4,0xCB} ,5);
Run Code Online (Sandbox Code Playgroud)

使用clang编译时会出现以下错误:

cccc.c:28:14: error: expected expression
Run Code Online (Sandbox Code Playgroud)

如果我修改它(参见额外的括号):

memcpy(dest,({0xAB,0x13,0xF9,0x93,0xB5}),5);
Run Code Online (Sandbox Code Playgroud)

clang给出的错误是:

cccc.c:26:14: warning: incompatible integer to pointer
              conversion passing 'int' to parameter of
              type 'const void *' [-Wint-conversion]

cccc.c:28:40: error: expected ';' after expression
memcpy(c+110,({0xAB,0x13,0xF9,0x93,0xB5}),5);
Run Code Online (Sandbox Code Playgroud)

那么,问题是:

如何传入硬编码数组作为memcpy(http://www.cplusplus.com/reference/cstring/memcpy/)的源参数

我试过了:

(void*)(&{0xAB,0x13,0xF9,0x93,0xB5}[0])  - syntax error
{0xAB,0x13,0xF9,0x93,0xB5}               - syntax error
({0xAB,0x13,0xF9,0x93,0xB5})             - see above
(char[])({0xE3,0x83,0xA2,0xA4,0xCB})     - error: cast to incomplete type 'char []' (clang)
Run Code Online (Sandbox Code Playgroud)

和一些更疯狂的组合我很惭愧写在这里......

请记住:我希望创建一个新的变量来保存阵列.

c arrays hardcoded

38
推荐指数
4
解决办法
4157
查看次数

为什么常量不是用于Node.js中的事件?

我是节点的新手,但我来自广泛的编程背景.在我看过的任何地方(无论是在教程中还是在我看过的生产代码中),人们都压倒性地使用硬编码字符串而不是常量来识别事件.

我从npm 最依赖的软件包列表中选择了一个随机的例子来说明我的意思:«请求»库 - 为什么它们每次都输入字符串来发出消耗 «data»事件'data',而不是在库中定义不变?

在我所知道的任何编程语言中,使用常量都被认为是一种很好的实践,但是节点开发人员似乎完全满足于硬编码方法.为什么?

javascript design-patterns constants hardcoded node.js

7
推荐指数
1
解决办法
260
查看次数

如何抑制FindBugs警告(硬编码引用绝对路径名)?

我只是测试开源软件Geonetwork的一些东西,现在我想将一个形状文件从我的postGIS数据库导出到我的计算机但我无法测试它因为我总是得到一个findbugs警告:硬编码引用org中的绝对路径名. fao.geonet.services.resources.Download.exec(Element,ServiceContext)

有谁知道如何抑制或避免这种警告?或者另一种解决方案我如何测试导出是否有效?

这是代码:

  ` Map parameter1= new HashMap();
    parameter1.put("dbtype", "postgis");        
    parameter1.put("host", "localhost");        
    parameter1.put("port", "5433");  
    parameter1.put("database", "geonetwork");
    parameter1.put("schema", "mydata");
    parameter1.put("user", "postgres");        
    parameter1.put("passwd", "dominik1");
    parameter1.put("Expose primary keys", false);
    parameter1.put(PostgisNGDataStoreFactory.VALIDATECONN, true);
    parameter1.put(PostgisNGDataStoreFactory.MAX_OPEN_PREPARED_STATEMENTS, 100);
    parameter1.put(PostgisNGDataStoreFactory.LOOSEBBOX, true);
    parameter1.put(PostgisNGDataStoreFactory.PREPARED_STATEMENTS, true); 
    System.out.println("parameter1: " + parameter1);

    DataStore pds = new PostgisNGDataStoreFactory().createDataStore(parameter1);
    FeatureSource fs = pds.getFeatureSource("dano");

    SimpleFeatureCollection fc = (SimpleFeatureCollection) fs.getFeatures();
    SimpleFeature f = (SimpleFeature) fc.toArray()[0];

    // create shapefile

    File sfile = new File("C:/Users/Tinis/Downloads/dano.zip");            
    parameter1 = new HashMap();
    parameter1.put("url", sfile.toURI().toURL());
    parameter1.put("create spatial index", Boolean.FALSE);


    DirectoryDataStore dds = new …
Run Code Online (Sandbox Code Playgroud)

java findbugs absolute-path suppress-warnings hardcoded

7
推荐指数
1
解决办法
6151
查看次数

检测硬编码密码

我一直在尝试检测源代码文件中的硬编码密码.

目前,我正在检查变量赋值和比较标识符,其子字符串与password,pswd匹配.

但它导致了许多误报,例如在这种情况下(从配置文件中读取密码)

String PASSWORD_KEY = "server.password";
String password = prop.getProperty(PASSWORD_KEY);
Run Code Online (Sandbox Code Playgroud)

我可以标出一些子字符串,如Key,location,path,我可以跳过错误生成但除此之外,我想不出更好的方法.

所有建议表示赞赏.

java security passwords hardcoded sonarqube

6
推荐指数
1
解决办法
1264
查看次数

在正则表达式中重用字符类

为了使正则表达式更加简短,是否有一种简写方法来引用同一正则表达式中较早出现的字符类?

例子

有没有办法缩短以下内容:

[acegikmoqstz@#&].*[acegikmoqstz@#&].*[acegikmoqstz@#&]

regex hardcoded character-class

5
推荐指数
1
解决办法
754
查看次数

是否可以使用硬编码的值列表而不是范围公式中的范围?

我想知道是否可以将数组或“范围”硬编码为公式。例如,如果我想查看 B2 中的一个月是三月、四月、六月还是七月,我想将其压缩:

=COUNTIF(a1:a4,MONTH(B2))>0
Run Code Online (Sandbox Code Playgroud)

其中 A1:a4 = 3,4,6,7

简单地说:

=COUNTIF((3,4,6,7),MONTH(B2))>0
Run Code Online (Sandbox Code Playgroud)

这样我就不需要其他单元格中的无关列表

excel static list formula hardcoded

5
推荐指数
1
解决办法
4426
查看次数

Java 获取 java.lang.Number 的通用子类或基元的 valueOf

在阅读了很多问题后,我问自己是否可以解决将字符串转换为通用数字而不使用硬编码方法的困境。

例如:我从方法中获取类型为 Class With Number.isAssignableFrom 的参数,或者通过其他方式检查这是否是数字类。但我也从用户那里得到了输入。作为一个字符串。

问题是:我现在可以以某种方式将此字符串转换为请求的数字对象,而无需为每种情况构建 if 语句吗?

示例代码,正常不起作用:

Object ret = null;

for(int i=0;i<method.getParameterTypes().length; i++ ) {
    Class<?> param = method.getParameterTypes()[i];
    String argString = getUserInput(_in, "Argument ("+param.getSimpleName()+"): ");

    if( Number.isAssignableFrom(param) )
        ret = ((Class<NumberChild>)param).valueOf(argString);
    /// OR
        ret = param.cast( Double.valueOf(argString) )
}
Run Code Online (Sandbox Code Playgroud)

甚至提出了这个问题:是否有可能将每个基元转换为与上述方式类似的东西?

注意:这里的方法应该完全关注非硬编码的解决方案。我当前运行的代码使用对每个案例进行硬编码的方法。但在这些情况下,更通用的解决方案会更有趣。

编辑: 我很抱歉造成误解,但我的意思是采用硬编码方法,这种方法可以测试每种可能的情况,例如:

 if( integer ); do ...
 if( double ); do ...
 if( long ); do ...
Run Code Online (Sandbox Code Playgroud)

但这正是我想要解决的问题。澄清一下:这只是一个挑战。我的生活或代码并不依赖于它,我只是想知道它是否可能!

java generics reflection casting hardcoded

5
推荐指数
2
解决办法
4038
查看次数

密码管理:html中的硬编码密码

Fortify列表输出以下行容易受到类别下的攻击 - Password Management : Hard coded Password.虽然我没有硬编码密码.为什么它显示为漏洞,我该如何解决?

txtPassword.style.visibility = "visible";
Run Code Online (Sandbox Code Playgroud)

提前致谢!

html security passwords hardcoded fortify

4
推荐指数
1
解决办法
2830
查看次数

C - 替代#ifdef

我正在尝试简化大量遗留C代码,其中,即使在今天,在构建维护它的人之前需要一个源文件,并在编译之前根据各种类型的环境手动修改以下部分.

这个例子如下,但这是问题所在.我的C上生锈了,但我记得不鼓励使用#ifdef.你们能提供更好的选择吗?另外 - 我认为其中一些(如果不是全部)可以设置为环境变量或作为参数传入,如果是这样 - 什么是定义这些然后从源代码访问的好方法?

这是我正在处理的代码片段

#define DAN          NO
#define UNIX         NO
#define LINUX        YES
#define WINDOWS_ES   NO
#define WINDOWS_RB   NO

/* Later in the code */
#if ((DAN==1) || (UNIX==YES))
#include <sys/param.h>
#endif

#if ((WINDOWS_ES==YES) || (WINDOWS_RB==YES) || (WINDOWS_TIES==YES))
#include <param.h>
#include <io.h>
#include <ctype.h>
#endif

/* And totally insane harcoded paths */
#if (DAN==YES)
char MasterSkipFile[MAXSTR] = "/home/dp120728/tools/testarea/test/MasterSkipFile";
#endif

#if (UNIX==YES)
char MasterSkipFile[MAXSTR] = "/home/tregrp/tre1/tretools/MasterSkipFile";
#endif

#if (LINUX==YES)
char MasterSkipFile[MAXSTR] = "/ptehome/tregrp/tre1/tretools/MasterSkipFile";
#endif …
Run Code Online (Sandbox Code Playgroud)

c conditional-compilation hardcoded c-preprocessor

4
推荐指数
2
解决办法
3281
查看次数

没有数据库永久保存php变量

在我的站点的管理区域中有一个表单,其中包含站点使用的mysql数据库的主机名,用户名和密码.目前,这些值被硬编码到php类中.但是谁可以链接它,以便表单可以编辑php类中的变量(并将结果保存在服务器上,换句话说,变量是硬编码的).我通常会将这样的事情保存在数据库中,但显然无法做到这一点.

php database variables save hardcoded

3
推荐指数
1
解决办法
2418
查看次数

结构硬编码初始化中的C结构

我在C99做错了什么:

struct chess {
    struct coordinate {
        char piece;
        int alive;
    } pos[3];
}table[3] =
{
    {
      {'Q', (int)1},{'Q', (int)1},{'Q', (int)1},
      {'B', (int)1},{'B', (int)1},{'B', (int)1},
      {'K', (int)1},{'K', (int)1},{'K', (int)1},
    }
};
Run Code Online (Sandbox Code Playgroud)

它给出了错误:

error: expected ‘:’, ‘,’, ‘;’, ‘}’ or ‘__attribute__’ before ‘=’ token
Run Code Online (Sandbox Code Playgroud)

我希望能够访问数据,例如在结构中具有结构:

table[row].pos[column].piece
table[row].pos[column].alive
Run Code Online (Sandbox Code Playgroud)

我尝试了几种组合,似乎没有一种组合适用于这种情况.在此之前我已经完成了之前的struct硬编码初始化,但这次不是结构中的结构.

有什么建议?

c struct c99 hardcoded

2
推荐指数
1
解决办法
673
查看次数

我们应该避免使用C++中的重复代码来成为"Pythonic",以及如何?

我正处于幼虫阶段,使用Python和C++中的预蛋阶段,但我正在尽我所能,特别是"不要重复自己"的原则.

我有一个多通道原始文件格式打开,主要的ascii标头,字段可表示为字符串和整数(总是编码为字符填充白色空格).第二部分是N个头部,其中N是主头部的字段,并且每个头部本身有更多的文本和数字字段(编码为ascii),指的是实际16比特多信道流的长度和大小组成文件的其余部分.

到目前为止,我在C++中有这个工作代码:

#include <iostream>
#include <sstream>
#include <fstream>
#include <string>
#include <map>

using namespace std;

struct Header {
    string version;
    string patinfo;
    string recinfo;
    string start_date;
    string start_time;
    int header_bytes;
    string reserved;
    int nrecs;
    double rec_duration;
    int nchannels;
};

struct Channel {
    string label;
    string transducertype;
    string phys_dim;
    int pmin;
    int pmax;
    int dmin;
    int dmax;
    string prefiltering;
    int n_samples;
    string reserved;
};


int main()
{
    ifstream edf("/home/helton/Dropbox/01MIOTEC/06APNÉIA/Samples/Osas2002plusQRS.rec", ios::binary);

    // prepare to read file header
    Header header;
    char buffer[80]; …
Run Code Online (Sandbox Code Playgroud)

c++ python abstraction repeat hardcoded

1
推荐指数
1
解决办法
569
查看次数